< previous page page_900 next page >

Page 900
b.IF time1 < time2
     Set n = 5
c. time1 >time2
     Set n = 8
d.IF time1 >time2
     Set n = 5
2. In reference to Programming Warm-Up Exercise 1, make life easier for the user of the TimeType class by adding new member functions NotEqual, LessOrEqual, GreaterThen and GreaterOrEqual to the class.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. Show the function specifications (prototypes and preconditions and postconditions) as they would appear in the new class declaration.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. Write the function definitions as they would appear in the implementation file. (Hint: Instead of writing the algorithms from scratch, simply have the function bodies invoke the existing functions Equal and LessThan. And remember: Class members can refer to each other directly without using dot notation.)
3. Enhance the TimeType class by adding a new member function WriteAmPm. This function prints the time in 12-hour rather than 24-hour form, adding AM or PM at the end. Show the function specification (prototype and precondition and postcondition) as it would appear in the new class declaration. Then write the function definition as it would appear in the implementation file.
4. Add a member function named Minus to the TimeType class. This valuereturning function yields the difference in seconds between the times represented by two class objects. Show the function specification (prototype and precondition and postcondition) as it would appear in the new class declaration. Then write the function definition as it would appear in the implementation file.
5. a. Design the data sets necessary to thoroughly test the LessThan function of the TimeType class.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. Write a driver and test the LessThan function using your test data.
6. a. Design the data sets necessary to thoroughly test the Write function of the TimeType class.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. Write a driver and test the Write function using your test data.
7. a. Design the data sets necessary to thoroughly test the WriteAmPm function of Programming Warm-Up Exercise 3.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. Write a driver and test the WriteAmPm function using your test data.
8. Reimplement the TimeType class so that the private data representation is a single variable:
long secs;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
This variable represents time as the number of seconds since midnight. Do not change the public interface in any way. The user's view is still hours, minutes, and seconds, but the class's view is seconds since midnight.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Notice how this data representation simplifies the Equal and LessThan functions but makes the other operations more complicated by converting seconds back and forth to hours, minutes, and seconds. Use auxiliary functions, hidden inside the implementation file, to perform these conversions instead of duplicating the algorithms in several places.

 
< previous page page_900 next page >