1: // Filenme: TESTIME2.CPP
2: // Purpose: Illustrates a simple time class, with the class accessed
3: // from a separate header (.H) file and separately compiled
4: // object (.OBJ) file. This driver tests the version of the
5: // Time class containing two constructors and two other functions.
7: #include <iostream>
8: using namespace std;
10: #include "TIME2.H"
11: #include "PAUSE.H"
13: void GetTimeFromUser(Time&);
14: Time IncrementedTime(const Time&, int);
17: int main()
18: {
19: cout << endl
20: << "This program illustrates the use "
21: << "of a simple time class with constructors. " << endl
22: << "You should study the source code "
23: << "at the same time as the output. " << endl
24: << endl;
26: Time t1(13, 21, 55);
27: Time t2;
28: t1.Display(); cout << endl;
29: t2.Display(); cout << endl;
30: Pause(0); cout << endl;
32: Time t3 = t1;
33: Time t4;
34: for (int i = 1; i <= 17; i++)
35: t1.Increment();
36: t4 = t1;
37: t3.Display(); cout << endl;
38: t4.Display(); cout << endl;
39: Pause(0); cout << endl;
41: Time myTime;
42: GetTimeFromUser(myTime);
43: myTime.Display(); cout << endl;
44: Pause(0); cout << endl;
46: int numberOfSeconds;
47: cout << "Enter a number of seconds to increment the time: ";
48: cin >> numberOfSeconds; cin.ignore(80, '\n'); cout << endl;
49: Time yourTime = IncrementedTime(myTime, numberOfSeconds);
50: yourTime.Display(); cout << endl;
51: Pause(0); cout << endl;
53: IncrementedTime(yourTime, 71).Display(); cout << endl;
54: cout << endl;
56: return 0;
57: }
60: void GetTimeFromUser(/* out */ Time& t)
61: // Pre: none
62: // Post: "t" contains a time value entered by the user from the keyboard.
63: {
64: int hours;
65: int minutes;
66: int seconds;
68: cout << endl;
69: cout << "Enter the hours, minutes and "
70: << "seconds for a time. " << endl
71: << "Enter the values in that order, "
72: << "separated by a blank space: ";
73: cin >> hours >> minutes >> seconds; cin.ignore(80, '\n');
74: cout << endl;
76: t.Set(hours, minutes, seconds);
77: }
80: Time IncrementedTime(/* in */ const Time& t,
81: /* in */ int numberOfSeconds)
82: // Pre: "t" contains a valid time value.
83: // Post: The return-value of the function is the time value obtained
84: // by incrementing "t" by numberOfSeconds seconds. The value
85: // of "t" itself is unchanged.
86: {
87: Time tempTime = t;
89: for (int i = 1; i <= numberOfSeconds; i++)
90: tempTime.Increment();
92: return tempTime;
93: }