Source of time5.h


  1: // TIME5.H
  2: // Specification file for a simple TimeType class with constructors
  3: // and access functions.

  5: #ifndef TIME5_H
  6: #define TIME5_H

  8: class TimeType
  9: {
 10: public:
 11:     // A new "four-in-one" constructor with "default parameter values".
 12:     TimeType(/* in */ int hoursInitial = 0,
 13:              /* in */ int minutesInitial = 0,
 14:              /* in */ int secondsInitial = 0);

 16:     // The following five "interface functions" are exactly the same
 17:     // as the correponding ones seen in T.
 18:     // For brevity we have omitted their pre- and post-conditions.
 19:     void Set(/* in */ int newHours,
 20:              /* in */ int newMinutes,
 21:              /* in */ int newSeconds);
 22:     void Increment();
 23:     int Hours() const;
 24:     int Minutes() const;
 25:     int Seconds() const;

 27:     // The following functions are "overloaded operators"
 28:     TimeType operator+(/* in */ const TimeType& otherTime) const;
 29:     // Pre:  self and otherTime have been initialized.
 30:     // Post: Value returned is equivalent self advanced by "otherTime".

 32:     bool operator==(/* in */ const TimeType& otherTime) const;
 33:     // Pre:  none
 34:     // Post: Function value returned is
 35:     //       - true, if this time equals otherTime
 36:     //       - false, otherwise

 38:     bool operator<(/* in */ const TimeType& otherTime) const;
 39:     // Pre:  This time and otherTime represent times in the same day.
 40:     // Post: Function value returned is
 41:     //       - true, if this time is earlier in the day than otherTime
 42:     //       - false, otherwise

 44:     friend ostream& operator<<(/* in */ ostream& outputStream,
 45:                                /* in */ const TimeType& t);
 46:     // Pre:  The output stream "outputStream" is open.
 47:     // Post: Time t has been output in the form HH:MM:SS.
 48:     //       "outputStream" is still open.

 50: private:
 51:     int hours;
 52:     int minutes;
 53:     int seconds;
 54: };

 56: #endif