Programming Assignments #1A and #1B:

Basics of User-defined Classes

Purpose: First exposure to user-defined classes. Declare, implement, and use your own DateType class. 

********************************************************************

 

First, download and unzip this zip file  to get the basic framework of the code in a Visual C++ project, which includes the following source code files:

 

·       DateType.h specifies the structure and the interface of the DateType class. Note that you should include the header file DateType.h in every .cpp file that uses the DateType class or implement the member functions of the DateType class. 

·       DateType.cpp implements the details of the member functions belonging to the DateType class;  

·       DateTest.cpp includes the header file DateType.h in order to use the DateType class. The main function in this file declares local DateType objects and calls the member functions of the DateType class in the context of these objects to test the implementation of the DateType class.

 

 

********************************************************************

 

Programming #1A  Steps:

1.     Play with the executable of a fully implemented sample version: Download play with this sample executable to get some sense of the behavior we want from the objects of the DateType class when the DateType class is fully implemented in the end of this programming assignment.

 

2.     Understand the code framework: Open the entire visual studio.NET project by double clicking the solution file under the project folder. Examine and understand (i) how the DateType class is declared in DateType.h and implemented in DateType.cpp and (ii) how the main function in DateTest.cpp declare and use objects of the DateType class to conduct tests on the DateType objects.

 

3.     Add code to complete the implementation of three existing simple member functions in the DateType class: Add your own code into DateType.cpp to complete the implementation of  the PrintDate member function, the ComparedTo member function and the ComparedCentury member function in DateType.cpp according to the specification commented in DateType.h.

 

4.     Test the implementation: uncomment the part of code labeled related to the R option (i.e. test 3) in the main function in DateTest.cpp and then run the program to test your implementation in step 3 above.

 

 

Submit your work for Programming #1A: Due Wednesday, Feb 5.

Submit all your source code files (.cpp and .h files) together with the self-evaluation report to the TA by the due date.

 

********************************************************************

 

 

Programming #1B  Steps:

 

5.     Revise the DateType class and add three new member functions into the class: Revise the declaration of DateType class in DateType.h to (i) add a new member function void AdvanceDays(int NumDays) that should modify the date by advancing it to a date NumDays days away in the future,  (ii) add a new member function void BackDays(int NumDays) that should modify the date by backing it down to a date NumDays days away in the past, and (iii) add a new member function bool IsValidDate(int newMonth, int newDay, int newYear) that would return true if the given information compose a valid date and return false otherwise. Remark: For the void AdvanceDays(int NumDays) member function, if it is called with a negative NumDays value, AdvanceDays(NumDays)  should work exactly like BackDays(-NumDays) to back up into the past. Similarly, for the void BackDays(int NumDays) member function, if it is called with a negative NumDays value, BackDays(NumDays)  should work exactly like AdvanceDays(-NumDays) to advance into the future.

6.     Notes about the implementation of AdvanceDays  (and BackDays similarly): The easiest way to advance the current date some (non-negative) NumDays days into the future is to (i) use a loop that repeats for NumDays iterations and (ii) for each iteration of the loop just advance the date one day into the future.  If you have time, there are additional things you can do to make it work even faster. For example, when NumDays is greater than 365, you can advance one year at a time (i.e. advancing 365 days or 366 days depending on whether Feb. 29 is encountered in the advancement). Similarly you can consider incorporation of advancing by month and advancing by century too.

 

7.     Add code to complete the implementation of the three new member functions above: Add code into DateType.cpp to implement the three new member functions above.

 

8.     Test the implementation: uncomment the part of code labeled as options A, B, and T (i.e. tests 4, 5, 6) in the main function in DateTest.cpp and then run the program to test your implementation in step 7 above to make sure you have correctly implemented the member functions as we want.

 

9.     Revise the implementation of three existing member functions to make them more robust: With the IsValidDate member function implemented, now you can call it to check whether it is a valid date given the day, the month, and the year as three integers. Now revise the implementation of your second constructor member function in DateType.cpp so that when an illegal date like 18/99/2003 is given they will output an error message and initialize the date to the date 1/1/2000 instead. Revise the implementation of your ReadDate member function in DateType.cpp so that if an invalid date is entered by the user it will keep informing the user it is not a valid date and asking for a new date until  a valid date is entered. Revise the implementation of the SetDate member function in DateType.cpp so that (i) when the given date information is valid, it will sets the date accordingly and return true and (ii)  when an illegal date like 18/99/2003 is given it will return false and leave the contents of  the date unchanged.

 

10.  Test the implementation: Run the program to test your implementation in step 9 above to make sure you have correctly implemented the member functions as we want.

 

 

Submit your work for Programming #1B: Due Wednesday, Feb 12.

Submit all your source code files (.cpp and .h files) together with the self-evaluation report to the TA by the due date.

 

********************************************************************