Programming Assignment #4: Defining a Class for Dates

 

 

1. First, define a new class, Date, as described below. (It is somewhat like a simplified version of the DateType class in our CSCI 106 class.)

·        Data members: Each of object of the Date class should have three data members(integers) to store the month, the day, and the year of the date.

·        Member functions:

o   Define a readDate method that will prompt the user to enter the day, the month, and the year of the date and store the information in the data members accordingly.

o   Define a printDate method that will print out the day, the month, and the year of the date currently recorded in the object.

o   Define a constructor that will allow the user to declare and initialize an object with the provided day, month, and year of the date to be recorded in the object in the beginning.

o   Define another constructor that will initialize the date recorded in the object as January 1st, 2000 when the object is declared without any specific date information given.

 

 

 

 

 

 

 

 

 

2. Second, after implementing the Date class above, do the following in your program to demonstrate the behavior we want from the Date class.

·        Create two objects of the Date class using the two different constructors.

·        Call the printDate method to see the contents of the two objects.

·        Call the readDate method to reset the dates in these two objects to different dates.

·        Call the printDate method again to see the contents of the two objects.