Chapter 9: Problem 13
Represent 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 \(^{11}\) in the present example is that class Professor inherits two names, one via Teacher and one via Scientist (both these classes inherit from Person). Neither of the two widely used languages Java and C# allow multiple inheritance. Nor in this book will we persue the idea of multiple inheritance further. Name of program file: Person.py.
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.