|
|
|
|
|
|
|
class Date
{
public:
void Print() const; // Output operation
void CopyFrom( /* in */ Date otherDate ); // Deep copy operation
Date( /* in */ int initMo, // Constructor
/* in */ int initDay,
/* in */ int initYr,
/* in */ const char* msgStr );
Date( const Date& otherDate ); // Copy-constructor
~Date(); // Destructor
private:
int mo;
int day;
int yr;
char* msg;
}; |
|
|
|
|
|
|
|
|
This class declaration includes function prototypes for all four of the member functions we said we are going to need: constructor, destructor, deep copy operation, and copy-constructor. Before proceeding, let's define more precisely the semantics of each member function by furnishing the function preconditions and postconditions. We have placed the complete specification of the Date class in its own figureFigure 17-10so that we can refer to it later. |
|
|
|
|
|
|
|
|
FIGURE 17-10 Specification of the Date Class |
|
|
|
|
|
|
|
|
//******************************************************************
// SPECIFICATION FILE (date.h)
// This file gives the specification of a Date abstract data
// type representing a date and an associated message
//******************************************************************
class Date
{
public:
void Print() const;
// Postcondition:
// Date and message have been output in the form
// month day, year message
// where the name of the month is printed as a string
void CopyFrom( /* in */ Date otherDate );
// Postcondition:
// This date is a copy of otherDate, including
// the message string |
|
|
|
|
|