Source of rem3.cpp


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

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

  8: #include "REM3.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 3) ... \n";
 27:     // Pause(0);  cout << endl;
 28: }


 31: //******************************************************************
 32: Reminder::~Reminder()
 33: {
 34:     delete [] messagePtr;

 36:     // Un-comment the following two lines for run-time confirmation
 37:     // that the destructor has been called:
 38:     // cout << "Now in the destructor for class Reminder (version 3) ... \n";
 39:     // Pause(0);  cout << endl;
 40: }


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

 53:     int year  = date/10000;
 54:     int month = date%10000 / 100;
 55:     int day   = date%10000 % 100;
 56:     cout << monthString[month-1] << ' ' << day << ", " << year << endl
 57:          << messagePtr << endl;
 58: }


 61: //******************************************************************
 62: void Reminder::MutilateMessageString()
 63: // Used only for pedagogical reasons to help show that only a
 64: // "shallow" copy of an object has been made.
 65: // Pre:  self has been initialized with a message of size >= 2.
 66: // Post: Alternate characters of the message pointed to by
 67: //       messagePtr have been changed to 'X'.
 68: {
 69:     for (int i = 0; i < strlen(messagePtr); i++)
 70:         if (i % 2 == 0) messagePtr[i] = 'X';
 71: }