Source of time4.h


  1: // Filename: TIME4.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 TIME4_H
  8: #define TIME4_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: public:

 30:     // A new "four-in-one" constructor with "default parameter values".
 31:     Time(/* in */ int hoursInitial   = 0,
 32:          /* in */ int minutesInitial = 0,
 33:          /* in */ int secondsInitial = 0);

 35:     // The following five "interface functions" are exactly the
 36:     // same as those in TIME3.H.  For brevity we have omitted the
 37:     // comments and pre/post-conditions, which are also the same.
 38:     // Note that the constructors and Display are missing.
 39:     // The constructors have been replaced by the new one above.
 40:     // Display will now be implemented as an overloaded operator,
 41:     // as will the (unique) equality operation and an add operation.
 42:     void Set(int hoursNew, int minutesNew, int secondsNew);
 43:     void Increment();
 44:     int Hours() const;
 45:     int Minutes() const;
 46:     int Seconds() const;


 49:     // The following two functions are also "overloaded operators",
 50:     // but are member functions.

 52:     Time operator+(/* in */ const Time& otherTime) const;
 53:     // Pre:  self and otherTime have been initialized.
 54:     // Post: Value returned is equivalent to self advanced by otherTime.

 56:     bool operator==(/* in */ const Time& otherTime) const;
 57:     // Pre:  none
 58:     // Post: Returns true if self equals otherTime and false otherwise.


 61: private:

 63:     int hours;
 64:     int minutes;
 65:     int seconds;
 66: };

 68: #endif