CS 111 - SUMMER 2002: Homework 5

Due: Monday, July 1

Reading: Chapter 6 and 7 and 8 (beginning), pages 427-432, 452-478, 523-547.


Reminder: Homework is due by 11:59 PM.

Program:

In this program you are to modify and combine two classes from the book into a new class DateandTime and test that your class works as specified. The two classes are the time class, found here and the date class found here. They can be found in the text on pages 423 and 429.

You should modify the time class so that it's print functions print out the date in addition to the time. So for example, the output might look like, 3:45 PM on March 5, 1999. You will not need the print function from the date class.

You should modify the date class to have two new member functions nextday, which will increment the day by one, to 12:00 AM of the next day, and nextmonth, which increments the month by one, to the beginning of the first day of the next month. Nextday may cause the date to change to the next month, or to the next year. (Remember the calendar program! You may need some of these ideas here.)

Finally you should combine the two classes into one class called DateandTime. In this new class you should have modified print functions which prints out both the time and the date, and the new member functions pertaining to the date.

The Test Program

In the file timetest.cpp you should write a "driver function" which tests out the capabilities of the new class. This program should include the incrementMinutes function found in Figure 6.10 and should also include one other function, addHour, which adds some hour(s) to the time. You should make sure that incrementMinutes and addHour will increment the next day or month or year when needed, depending on the current time and date. When writing these increment functions you should take the incrementMinutes function found in Figure 6.10 of the text as your model. In particular, these functions should take as input a DateandTime object and an integer. The DateandTime object should be passed as a reference parameter.

The input to this test program can either come by entering the data from the terminal as it is asked for, or by putting the date and time data directly in the program. In either case the program should test out the capabilities of the new class and its methods. When you look at the output, you should be able to see that it keeps track of a date and time, adding days, hours, seconds to it as requested and moving from one hour or day to the next correctly. (For example, show that when you add 2 hours to 11:15 PM on Feb 28, 2004 then the new time and date is 1:15 A.M. on Feb 29, 2004. )

What To Submit

The files you must submit for this homework are exactly DateandTime.h which contains your header file, DateandTime.cpp which contains your class method definitions, timetest.cpp which contains your program, and homework5.scr, a script file which contains a script session showing the program, its compilation, and its output on the test files. To do this you need to use the gsubmit program and remember to put the files you want to submit into a directory called hw5 and gsubmit hw5 to the class cs111a2. There is a pointer to gsubmit information on the class home page.


Academic Honesty and Collaboration

It is reasonable to discuss with others possible general approaches to problems. It is unreasonable to work together on a detailed solution, to copy a solution, or to give away a solution. If your common discussion can be detected by looking at the solutions, then there is too much collaboration. Such instances of academic dishonesty will result in a course grade of F or expulsion from Boston University.

Do not allow your work to be used by others:

Warning: If someone cheats by using your work, you will also be penalized


Page Created: May 25, 2002