CS12, Program 5
Assigned:
November 29th, 2001
Due:
December 9th, 2001, 11pm
Topics
·
Inheritance
·
Operator overloading
·
More practice with Unix and makefiles
Background
In several of the labs this quarter, you worked with the Time
class that appears in chapters 6 and 7 of your book. In this assignment, you will inherit another
class from this class.
To Do
Start with one of the versions of the time class from the book
(time3, on pages 423--424, or time5, pages 455--457). Put your class in
a files called time.h and time.cc, and call the class Time.
Write another class, ZonedTime, that inherits from the Time class,
but also contains an additional private member, time_zone. For the
purposes of this assignment, implement only the four time zones of the
continental US: Easter, Central, Mountain and Pacific. Write a
constructor for your class that will allow you to set both the time and
the time zone for an object.
Override the print methods of this class so that they print the time
zone as well as military time.
Overload the equality comparison operator
(==) for the ZonedTime class to compare two ZonedTime objects and see if
they show the same
time. For example, 09:13:46 Eastern is the same time as 06:13:46 Pacific,
but 20:15:00 Central is not the same time as 20:15:00 Pacific.
Write a short main program that tests your
Time and ZonedTime classes. Initialize some objects of each class and
print them out using the << operator. Then compare some ZonedTime
objects to see if your == operator is functioning properly.
What to turn in
·
time.h
·
time.cc
·
zonedtime.h
·
zonedtime.cc
·
main.cc
·
A makefile that will compile the program when the
user types "make all", creating an executable called "run".