|
|
|
|
|
|
|
#include <iostream.h>
#include timetype.h
int main()
{
TimeType time;
int hours;
int minutes;
int seconds;
cout << Enter a time (use hours < 0 to quit): ;
cin >> hours >> minutes >> seconds;
while (hours >= 0)
{
time.Set(hours, minutes, seconds);
time.Increment();
cout << Incremented time is ;
time. Write ();
cout << endl;
cout << Enter a time (use hours < 0 to quit): ;
cin >> hours >> minutes >> seconds;
}
return 0;
} |
|
|
|
|
|
|
|
|
The timetype.cpp implementation file only needs to contain function definitions for the following member functions: Set, Increment, Write, and the default constructor. The other member functions do not need to be implemented yet. Now we compile the test driver and timetype.cpp, link the two object files, and execute the program. For input data we supply at least the four test cases discussed earlier. The program's output should match the desired results. |
|
|
|
|
|
|
|
|
Now that we have tested the Increment function, we can apply the same steps to the remaining class member functions. We can create a separate test driver for each function or we can write just one driver that tests all of the functions. The disadvantage of writing just one driver is that devising different combinations of input values to test several functions at once can quickly become complicated. |
|
|
|
|
|
|
|
|
Before leaving the topic of testing a class, we must emphasize an important point. Even though a class has been tested thoroughly, it is still possible for bugs to arise. Let's look at two examples using the TimeType class. The first example is the client statement |
|
|
|
|
|