Lab 6 - Inheritance and Polymorphism

Due: 5:00pm on Wednesday

The purpose of this lab is to add the polymorphic function printDate() to the Date and DateTime classes discussed in lecture. You will also be adding the copy constructor and assignment operator to the DateTime class.

Copy the file lab6.cpp to your current directory using either wget or cut-and-paste as described in previous labs. This file contains portions of the Date and DateTime classes as well as the main() function. The file will NOT compile until you add the printDate() function.

The Date version of printDate() will output the current year, month and day in the format yyyy/mm/dd. The DateTime version of printDate() will output the date in this same format and the time as hh:mm (24 hour time).

You will also need to add the copy constructor and assignment operator to the child class DateTime. The copy constructor will invoke Date's version of the copy constructor to set the year, month and day and it will then copy the hour and minute. Likewise the assignment operator will invoke Date's version of the assignment operator to set the date and then copy the time. The syntax to do this was discussed in class Friday and can also be found in the textbook or in the Savitch textbooks found in the walk-in lab.

Once you have added printDate() and DateTime's copy constructor and assignment operator, the provided main() will compile. If you have done your polymorphic printDate() correctly, you should see the pointer invoking first Date's version then DateTime's version. If you see Date's version twice, you have not properly marked printDate() as polymorphic.

Turn in your fully updated lab6.cpp with these features added.