|
|
|
|
|
|
|
RelationType ComparedTo( /* in */ DateType otherDate ) const;
// Postcondition:
// Function value == BEFORE, if this date is
// before otherDate
// == SAME, if this date equals otherDate
// == AFTER, if this date is
// after otherDate
void Increment();
// Postcondition;
// Date has been advanced by one day
DateType();
// Postcondition:
// New DateType object is constructed with a
// month, day, and year of 1, 1, and 1583
private:
int mo;
int day;
int yr;
}; |
|
|
|
|
|
|
|
|
Implementation of the ADT: We have already chosen a concrete data representation for a date, shown in the specification file as the int variables mo, day, and yr. Now we must implement each class member function, placing the function definitions into a C++ implementation file named, say, datetype.cpp. As we implement the member functions, we also discuss testing strategies that can help to convince us that the implementations are correct. |
|
|
|
|
|
|
|
|
The class constructor, Set, Month, Day, and Year functions: The implementations of these functions are so straightforward that no discussion is needed. |
|
|
|
|
|
|
|
|
The class constructor DateType() |
|
|
|
|
|
|
|
|
Set mo = 1
Set day = 1
Set yr = 1583 |
|
|
|
|
|
|