Source of date4.h


  1: // Filename: DATE4.H
  2: // Purpose:  Specification file for a simple Date class.

  4: class Date
  5: {
  6: public:
  7:     Date();
  8:     // Default constructor
  9:     // Pre:  none
 10:     // Post: month == 1  and  day == 1  and  year == 1970
 11:     //       and *messagePtr == "No message ..."

 13:     Date(/* in */ int         newMonth,
 14:          /* in */ int         newDay,
 15:          /* in */ int         newYear,
 16:          /* in */ const char* messageString);
 17:     // Constructor
 18:     // Pre:      1 <= newMonth <= 12
 19:     //       and 1 <= newDay   <= maximum number of days in newMonth
 20:     //       and 1970 <= newYear
 21:     //       and messageString is initialized
 22:     // Post: New class object is constructed with a date of newMonth,
 23:     //       newDay, newYear and the message string in messageString.

 25:     Date(const Date& otherDate);
 26:     // Copy constructor
 27:     // Pre:  otherDate has been initialized.
 28:     // Post: A new class object is constructed with its date and
 29:     //       message string the same as otherDate's.
 30:     //       Note:
 31:     //       This constructor is implicitly invoked whenever:
 32:     //       - A Date object is passed by value, or
 33:     //       - A Date object is returned as a function value, or
 34:     //       - A Date object is initialized by another Date object
 35:     //         in a declaration

 37:     void operator=(const Date& rightSide);
 38:     // Pre:  rightSide has been initialized.
 39:     // Post: A "deep" copy of rightSide has been made and assigned
 40:     //       to the Date object on the left side of the assignment
 41:     //       operator =.

 43:     void Display() const;
 44:     // Pre:  self is initialized.
 45:     // Post: Date and message have been output in the form
 46:     //       month day, year       message
 47:     //       in which the name of the month is displayed as a string,
 48:     //       and the message string is displayed on the line beneath
 49:     //       the date.

 51:     ~Date();
 52:     // Destructor
 53:     // Pre:  self is initialized.
 54:     // Post: Message string pointed to by messagePtr has been deleted.

 56:     void InsertXX();
 57:     // Used only for pedagogical reasons to help show that only a
 58:     // "shallow" copy of an object has been made.
 59:     // Pre:  self has been initialized with a message of size <= 2.
 60:     // Post: The first two characters of the message pointed to by
 61:     //       messagePtr have been changed to 'X'.

 63: private:
 64:     int   day;
 65:     int   month;
 66:     int   year;
 67:     char* messagePtr;
 68: };