Chapter 9: Problem 6
Make super- and subclass for a point.
A point
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.
Chapter 9: Problem 6
Make super- and subclass for a point.
A point
These are the key concepts you need to understand to accurately answer the question.
All the tools & learning materials you need for study success - in one app.
Get started for freeRepresent people by a class hierarchy.
Classes are often used to model objects in the real world. We may represent
the data about a person in a program by a class Person, containing the
person's name, address, phone number, date of birth, and nationality. A method
__str__ may print the person's data. Implement such a class Person.
A worker is a person with a job. In a program, a worker is naturally
represented as class Worker derived from class Person, because a worker is a
person, i.e., we have an is-a relationship. Class Worker extends class Person
with additional data, say name of company, company address, and job phone
number. The print functionality must be modified accordingly. Implement this
Worker class.
A scientist is a special kind of a worker. Class Scientist may therefore be
derived from class Worker. Add data about the scientific discipline (physics,
chemistry, mathematics, computer science,...). One may also add the type of
scientist: theoretical, experimental, or computational. The value of such a
type attribute should not be restricted to just one category, since a
scientist may be classified as, e.g., both experimental and computational
(i.e., you can represent the value as a list or tuple). Implement class
Scientist.
Researcher, postdoc, and professor are special cases of a scientist. One can
either create classes for these job positions, or one may add an attribute
(position) for this information in class Scientist. We adopt the former
strategy. When, e.g., a researcher is represented by a class Researcher, no
extra data or methods are needed. In Python we can create such an "empty"
class by writing pass (the empty statement) as the class body:
It is a continuous debate in computer science whether multiple inheritance is
a good idea or not. One obvious problem
Make a calculus calculator class.
Given a function
Compute convergence rates of numerical integration methods.
Most numerical methods have a discretization parameter, call it
Make circle a subclass of an ellipse.
Chapter
What do you think about this solution?
We value your feedback to improve our textbook solutions.