Source of date3.cpp


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

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

  8: //******************************************************************
  9: Date::Date()
 10: {
 11:     month = 1;
 12:     day = 1;
 13:     year = 1970;
 14:     messagePtr = new char[strlen("No message ...") + 1];
 15:     strcpy(messagePtr, "No message ...");
 16: }

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

 31: //******************************************************************
 32: void Date::Display() const
 33: {
 34:     static char monthString[12][10] =
 35:     {
 36:         "January", "February", "March", "April", "May", "June",
 37:         "July", "August", "September", "October", "November",
 38:         "December"
 39:     };
 40:     cout << monthString[month-1] << ' ' << day << ", " << year << endl
 41:          << messagePtr << endl;
 42: }

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

 52: //******************************************************************
 53: void Date::InsertXX()
 54: {
 55:     messagePtr[0] = 'X';
 56:     messagePtr[1] = 'X';
 57: }