class Time
1: /** @file time.h
2: Specification file corresponding to time.cpp.
3: This class illustrates three overloaded operators and the
4: use of default parameters to combine constructor definitions.
5: @author Scobey:Porter:A00123456:CSC34101
6: @date October 5, 2010
7: @version 2.0
8: */
10: #ifndef TIME_H
11: #define TIME_H
13: class Time
14: {
15: //The following two functions are "overloaded operators",
16: //implemented as friend functions.
18: friend istream& operator>>
19: (
20: istream& inputStream, //inout
21: Time& t //out
22: );
23: /**<
24: Reads a Time value from an input stream.
25: @return A reference to the input stream from which the
26: Time value is read.
27: @param inputStream The input stream from which the Time
28: value is read.
29: @param t The variable in which the Time value is stored.
30: @pre The input stream inputStream is open.
31: @post
32: - A TIme value having the format HH:MM:SS has been
33: read from the input stream and placed in t.
34: - inputStream is still open.
35: */
37: friend ostream& operator<<
38: (
39: ostream& outputStream, //inout
40: const Time& t //in
41: );
42: /**<
43: Writes a Time value to an output stream.
44: @return A reference to the output stream to which the
45: Time value is written.
46: @param outputStream The output stream to which the Time
47: value is written.
48: @param t The Time value to be written to the output stream.
49: @pre
50: - The output stream outputStream is open.
51: - Time t has been initialized.
52: @post
53: - The value of Time t has been output in the format HH:MM:SS.
54: - outputStream is still open.
55: */
57: public:
59: //A "four-in-one" constructor with "default parameter values".
60: Time
61: (
62: int hoursInitial = 0, //in
63: int minutesInitial = 0, //in
64: int secondsInitial = 0 //in
65: );
66: /**<
67: Constructs a time object with hours, minutes and seconds
68: set to the input parameter values, or to 0 by default.
69: @pre
70: - 0 <= hoursNew <= 23
71: - 0 <= minutesNew <= 59
72: - 0 <= secondsNew <= 59
73: @post A Time object has been constructed according to
74: the values of the incoming (or default) parameters.
75: */
78: void set
79: (
80: int hoursNew, //in
81: int minutesNew, //in
82: int secondsNew //in
83: );
84: /**<
85: Sets (or resets) the value of the current Time object.
86: @pre
87: - 0 <= hoursNew <= 23
88: - 0 <= minutesNew <= 59
89: - 0 <= secondsNew <= 59
90: @post The current Time object has been set according
91: to the values of the incoming parameters.
92: */
95: //Getters for hours, minutes and seconds from a Time object
96: int getHours() const;
97: /**<
98: @return The hours component of the current Time value.
99: @pre This Time object has been initialized.
100: @post No side effects.
101: */
103: int getMinutes() const;
104: /**<
105: @return The minutes component of the current Time value.
106: @pre This Time object has been initialized.
107: @post No side effects.
108: */
110: int getSeconds() const;
111: /**<
112: @return The seconds component of the current Time value.
113: @pre self has been initialized.
114: @post No side effects.
115: */
118: void increment();
119: /**<
120: Increases the value of the current Time object by 1 second.
121: @return void
122: @pre self has been initialized.
123: @post self has been advanced by one second, with
124: 23:59:59 wrapping around to 00:00:00 if necessary.
125: */
128: //The following two functions are also "overloaded operators",
129: //but are member functions.
131: Time operator+
132: (
133: const Time& otherTime //in
134: ) const;
135: /**<
136: Adds another Time object to self.
137: @return The Time object resulting from the additon.
138: @param otherTime The Time object to be added to self.
139: @pre self and otherTime have been initialized.
140: @post Value returned is equivalent to self advanced by otherTime.
141: */
143: bool operator==
144: (
145: const Time& otherTime //in
146: ) const;
147: /**<
148: Determines if self is equal to another Time object.
149: @return <tt>true</tt> if self equals otherTime and
150: <tt>false</tt> otherwise.
151: @param otherTime The %Time object against which self is being compared.
152: @pre self and otherTime have been initialized.
153: @post No side effects.
154: */
156: private:
157: int hours; //hours component of the current Time
158: int minutes; //minutes component of the current Time
159: int seconds; //seconds component of the current Time
160: };
162: #endif