Source of date2.cpp


  1: // Filename: DATE2.CPP
  2: // Purpose:  Implementation file corresponding to DATE2.H.

  4: #include "date2.h"
  5: #include <iostream>
  6: #include <string.h>   // For strcpy() and strlen()

  8: // Private members of class:
  9: //     int   month;
 10: //     int   day;
 11: //     int   year;
 12: //     char* messagePtr;

 14: //******************************************************************
 15: Date::Date(/* in */ int         newMonth,
 16:            /* in */ int         newDay,
 17:            /* in */ int         newYear,
 18:            /* in */ const char* messageString)
 19: {
 20:     month = newMonth;
 21:     day = newDay;
 22:     year = newYear;
 23:     messagePtr = new char[strlen(messageString) + 1];
 24:     strcpy(messagePtr, messageString);
 25: }


 28: //******************************************************************
 29: void Date::Display() const
 30: {
 31:     static char monthString[12][10] =
 32:     {
 33:         "January", "February", "March", "April", "May", "June",
 34:         "July", "August", "September", "October", "November",
 35:         "December"
 36:     };

 38:     cout << monthString[month-1] << ' ' << day << ", " << year << endl
 39:          << messagePtr << endl;
 40: }


 43: //******************************************************************
 44: Date::~Date()
 45: {
 46:     delete [] messagePtr;
 47:     cout << "Now in the destructor for class Date ... " << endl;
 48:     Pause();  cout << endl;
 49: }