1: // Filename: REM1.CPP 2: // Purpose: Implementation file corresponding to REM1.H. 4: #include <iostream> 5: #include <cstring> 6: using namespace std; 8: #include "REM1.H" 9: #include "PAUSE.H" 11: // Private members of class: 12: // int date; 13: // char* messagePtr; 15: //****************************************************************** 16: Reminder::Reminder(/* in */ int date, 17: /* in */ const char* messageString) 18: // Constructor 19: // Pre: 19700101 <= date <= 29990101, and 20: // messageString has been initialized. 21: // Post: A new class object has been constructed, 22: // having the input date and messageString. 23: { 24: this->date = date; 25: messagePtr = new char[strlen(messageString) + 1]; 26: strcpy(messagePtr, messageString); 28: // Un-comment the following two lines for run-time confirmation 29: // that this constructor has been called: 30: // cout << "Now in constructor for class Reminder (version 1) ... \n"; 31: // Pause(); cout << endl; 32: } 35: //****************************************************************** 36: void Reminder::Display() const 37: // Pre: self is initialized. 38: // Post: Date and message have been output in the (typical) form: 39: // April 20, 1944 40: // This is somebody's birthday. 41: // in which the name of the month is displayed as a string, and 42: // the message string is displayed on the line beneath the date. 43: { 44: static char* monthString[12] = 45: { 46: "January", "February", "March", "April", 47: "May", "June", "July", "August", 48: "September", "October", "November", "December" 49: }; 51: int year = date/10000; 52: int month = date%10000 / 100; 53: int day = date%10000 % 100; 54: cout << monthString[month-1] << ' ' << day << ", " << year << endl 55: << messagePtr << endl; 56: }