1: // Filenme: TESTIME3.CPP
2: // Purpose: Uses the Time class to compare member, non-member and
3: // friend functions.
6: #include <iostream>
7: using namespace std;
10: #include "TIME3.H"
11: #include "PAUSE.H"
14: bool EqualTo2(/* in */ const Time& t1,
15: /* in */ const Time& t2);
18: int main()
19: {
20: cout << endl
21: << "This program uses the Time class to "
22: << "compare member, non-member and friend " << endl
23: << "functions. You should study the source "
24: << "code at the same time as the output. " << endl << endl;
26: Time t1(11, 59, 50);
27: Time t2(12, 0, 0);
29: t1.Display(); cout << endl;
30: t2.Display(); cout << endl;
31: Pause(0);
33: if (t1.EqualTo1(t2))
34: cout << "The two times are equal." << endl;
35: else
36: cout << "The two times are not equal." << endl;
37: Pause(0);
39: while (!EqualTo2(t1, t2))
40: {
41: t1.Display(); cout << endl;
42: t1.Increment();
43: }
44: Pause(0);
46: if (EqualTo3(t1, t2))
47: cout << "The two times are equal." << endl;
48: else
49: cout << "The two times are not equal." << endl;
51: return 0;
52: }
57: // Note that the following function is just an "ordinary"
58: // function (not a member function and not a friend function)
59: // and hence it must use the "accessor" functions to obtain the
60: // values of the private data members.
61: bool EqualTo2(/* in */ const Time& t1,
62: /* in */ const Time& t2)
63: // Pre: t1 and t2 have been initialized.
64: // Post: Returns true if t1 and t2 are the same Time value
65: // and false otherwise.
66: {
67: return (t1.Hours() == t2.Hours() &&
68: t1.Minutes() == t2.Minutes() &&
69: t1.Seconds() == t2.Seconds());
70: }