Source of t4.h
class Time
1: // Filename: T4.H
2: // Purpose: Specification file corresponding to TIME4.CPP.
3: // This version adds three overloaded operators and default
4: // parameters in order to combine constructor definitions.
7: #ifndef _T4_H_
8: #define _T4_H_
11: class Time
12: {
13: // The following two functions are "overloaded operators",
14: // implemented as friend functions.
16: friend istream& operator>>(/* inout */ istream& inputStream,
17: /* out */ Time& t);
18: // Pre: The output stream outputStream is open.
19: // Post: Time t has been output in the form HH:MM:SS.
20: // outputStream is still open.
22: friend ostream& operator<<(/* inout */ ostream& outputStream,
23: /* in */ const Time& t);
24: // Pre: The output stream outputStream is open.
25: // Post: Time t has been output in the form HH:MM:SS.
26: // outputStream is still open.
28: friend Time operator +(/* in */ const Time& t1,
29: /* in */ const Time& t2);
30: // Pre: t1 and t2 have been initialized.
31: // Post: Value returned is equivalent to t1 advanced by t2.
33: public:
35: // A new "four-in-one" constructor with "default parameter values".
36: Time(/* in */ int hoursInitial = 0,
37: /* in */ int minutesInitial = 0,
38: /* in */ int secondsInitial = 0);
40: // The following five "interface functions" are exactly the
41: // same as those in TIME3.H. For brevity we have omitted the
42: // comments and pre/post-conditions, which are also the same.
43: // Note that the constructors and Display are missing.
44: // The constructors have been replaced by the new one above.
45: // Display will now be implemented as an overloaded operator,
46: // as will the (unique) equality operation and an add operation.
47: void Set(int hoursNew, int minutesNew, int secondsNew);
48: void Increment();
49: int Hours() const;
50: int Minutes() const;
51: int Seconds() const;
54: // The following two functions are also "overloaded operators",
55: // but are member functions.
57: bool operator==(/* in */ const Time& otherTime) const;
58: // Pre: none
59: // Post: Returns true if self equals otherTime and false otherwise.
62: private:
64: int hours;
65: int minutes;
66: int seconds;
67: };
69: #endif