Source of rem2.cpp


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

  4: #include <iostream>
  5: #include <cstring>
  6: using namespace std;

  8: #include "REM2.H"
  9: #include "PAUSE.H"


 12: // Private members of class:
 13: //     int   date;
 14: //     char* messagePtr;

 16: //******************************************************************
 17: Reminder::Reminder(/* in */ int date,
 18:                    /* in */ const char* messageString)
 19: {
 20:     this->date = date;
 21:     messagePtr = new char[strlen(messageString) + 1];
 22:     strcpy(messagePtr, messageString);

 24:     // Un-comment the following two lines for run-time confirmation
 25:     // that this constructor has been called:
 26:     // cout << "Now in constructor for class Reminder (version 2) ... \n";
 27:     // Pause(0);  cout << endl;
 28: }


 31: //******************************************************************
 32: Reminder::~Reminder()
 33: // Destructor
 34: // Pre:  self is initialized.
 35: // Post: Message string storage pointed to by messagePtr
 36: //       has been deallocated.
 37: {
 38:     delete [] messagePtr;

 40:     // Un-comment the following two lines for run-time confirmation
 41:     // that the destructor has been called:
 42:     // cout << "Now in the destructor for class Reminder (version 2) ... \n";
 43:     // Pause(0);  cout << endl;
 44: }


 47: //******************************************************************
 48: void Reminder::Display() const
 49: {
 50:     static char* monthString[12] =
 51:     {
 52:         "January",   "February", "March",    "April",
 53:         "May",       "June",     "July",     "August",
 54:         "September", "October",  "November", "December"
 55:     };

 57:     int year  = date/10000;
 58:     int month = date%10000 / 100;
 59:     int day   = date%10000 % 100;
 60:     cout << monthString[month-1] << ' ' << day << ", " << year << endl
 61:          << messagePtr << endl;
 62: }