CS-183 Homework Assignment 3
Dr. Mark J. Sebern
Assignment
Please complete the following exercise:
- Design an inheritance hierarchy with at least three classes (at least one base class and
two derived classes), based on some application domain of your choosing. Some possible
domains are suggested in exercises 13.1 to 13.7 on pages 706-707 of the textbook, but you
are encouraged to think up your own. The use of multiple inheritance is discouraged unless
there is a compelling need for it.
You should create:
- A well-commented class definition (.h) file.
- An implementation (.cpp) file.
- A simple example program.
You are encouraged to add extra output messages (e.g., "base class constructor
called") so that you can better visualize the operation of the classes with
inheritance. One problem is getting what would normally be console output into a file.
There are several ways to do this, including:
- Run the program from a console command line and redirect the standard output into a file
using the ">" redirection operator (e.g., "myprog >myprog.txt").
- Define a global ofstream object and insert output into this object from
the various member functions. (This is one case, for visualization purposes, that a global
object may be justified.)
The purpose of this program is to give you a chance to experiment with a simple
inheritance hierarchy. Don't get carried away with the level of complexity, but do try out
a few different aspects of inheritance, such as:
- Order of invocation of base class and derived class constructors and destructors when a
derived-class object comes into and goes out of existence.
- Overriding of member functions.
- Use of constructors other than the "no-argument" one to initialize a
base-class subobject or derived-class data member.
Submission
The assignment (in one text file, including any program output) should be
submitted by email to Dr. Sebern. Please keep a
backup copy in case your work gets lost in the email system. Please be sure to include
your name in the assignment text file.
This assignment is due before the start of class on Monday of week 8.
If you have any questions, or any part of the assignment is unclear, please consult the
instructor.
This page was last updated on May 02, 1999; send comments to Mark Sebern.
Copyright information