 # CHAPTER 11 8. Consider the design of a class for managing the Olym...

## Question

CHAPTER 11
8. Consider the design of a class for managing the Olympics—to simplify things, consider management of Olympic medal awards. Design a medal class.

• Fields: Name of the athlete, country, event, medal type (gold, silver, bronze)
• Methods: get, set, and so on.

CHAPTER 12

3. The human body has many organs (heart, lungs, brain, and kidneys, to name a few). We could think of the human body as a complex object made up of simpler objects (organs).

a. Create classes for heart and brain. Think about what the functions of the heart and brain are in our body and map these functions into methods.
b. Create an Organ class as the base class for the organs and derive the classes created earlier from the base class.

6. In Newtonian physics, we know that two velocities in the same direction add to each other; in the opposite direction, they subtract from each other to give a net result in the direction of the bigger velocity. Design a simple class called Velocity that has a field for the speed in meters per second. (Forget about the direction for now). The default constructor would work with meters/sec metric. Write a constructor that takes three parameters: (a) distance, (b) time, and (c) whether the velocity is in meters/sec or feet/sec. This constructor should accordingly convert the feet/sec into meters/sec. Create overloaded unary, addition, and subtraction operators for velocity. A more advanced version of this class would consider the directions other than same or opposite directions.

8. File Concatenation: Many operating systems allow one to concatenate files. Design a class called TextDocument that reads the contents of a text file only. Create a constructor that takes the path of a text file. Create an overloaded addition operator for this class that adds (concatenates) two TextDocument objects (appends the second one at the end of the first one) and creates a new text file. Handle all possible error cases, such as for file existence.

9. Consider a specific type of chemical reaction that takes in two compounds and returns a new compound. Design a class called Compound with fields for the name of the compound (such as hydrochloric acid), chemical formula of the compound (HCl). Create an addition operator for the compound class so that when you add two compounds, you get a new one. In the operator function, just print a string indicating the two compounds being added.

14. Write a class for linear equations. A generic linear equation is of the form y = mx + b where m and b are constants. Include the following methods:

a. __init__, __str__ , __repr__.
b. value(x), which returns the value of the equation given x.
c. compose(linearEquation) that composes two linear equations. That is, if y = x +1 and z = 2a+5, then y(z) = 2x +6 and will be called as y.compose(z). Note that the compose operation is not commutative.
d. __add__ returns the sum of two linear equations. That is, if y = ax + b and
z = cx + d , then y + z = (a + c )x + (b + d).

Include sample code that uses your class and demonstrates the use of all methods as well as error handling.

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

"""
Name: XXXX
Class: XXXX
Date:

Homework Problem: Ch 12 No. 3

The Organ class is the base class containing basic
information about the organ, Brain and Heart class
derived from the organ class.
"""
class Organ:
def __init__(self, name):
"""
The super class constructor
:param name: the name of the organ.
"""
self.__name = name

def get_name(self):
"""
It returns the name of the organ.
:return: the name of the organ.
"""
return self.__name

def __str__(self):
"""
It returns the string representation
of the organ instance.
:return: the string containing name of the organ
"""
return self.get_name()

class Heart(Organ):

def __init__(self, name):
"""
The constructor to initialize the heart class instance,
it also calls the super class constructor.
:param name: the name of the organ
"""
Organ.__init__(self, name=name)

def work(self):
"""
The work method which prints the working
of this organ.
:return: None
"""
print("Pumping blood")

class Brain(Organ):...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

\$30.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.