Dana Vrajitoru
C201/I211 Computer Programming II
Homework 12
Due Date: Wednesday, December 6, 2006.
Ex. 1 Design and implement a project containing at least
three classes, the first being a general category, the second one
derived from it, and the third one derived from the second, after the
model of the Socrates program discussed in class.
General requirements:
- Each class should declare at least 2 data members as
protected. There should be at least an accessor function for each of
them (as the function Is_alive is for the data member life_flag in the
class Lifeform) and mutator functions when appropriate (like the
function Die for the same life_flag).
- Each class should implement at least one constructor. The
constructor(s) of the derived class should invoke a constructor of the
base class.
- Each class should implement at least two other class methods
declared as public. One of these class methods should be implemented
with the same name in at least one base class and one derived class,
as an example of redefining/overloading a class method, as it is the
case for the function Walk in the Socrates example.
- The main should contain some examples of declaring objects from
each of your classes and of calling the available methods for each of
them.
Ideas:
- Any three categories in the natural systems other than lifeform,
animal and human - plants, specific types of animals, reptiles,
mammals, birds, etc.
- Utility objects: vehicles of different categories, inanimate
objects followed by human made machines and robots, and so on.
- Different types of products to be sold in a shop, provided that
you don't reuse the class Product defined before.
- A general file category, followed by a viewable file and then
image file or text file.
- Different categories for professions, anything other than student
and teacher.
Note. Do not implement the same classes as someone else. You
can have at most one class name in common with someone else, but the
content of the class should be different.
Example The following files constitute the program
implementing the Socrates example, along with a Makefile for
compilation on Linux:
animal.cpp
animal.h
human.cpp
human.h
lifeform.cpp
lifeform.h
main.cpp
Makefile
Turn in: all the files in your project (.cpp and .h). If you
create a Makefile, send it in too.