|
|
|
|
|
|
|
Notice the preconditions for the Increment, Write, Equal, and LessThan functions. It is the responsibility of the client to set the time before incrementing, printing, or testing it. If the client fails to set the time, the effect of each of these functions is undefined. |
|
|
|
|
|
|
|
|
In principle, a specification file should not reveal any implementation details to the user of the class. The file should specify what each member function does without disclosing how it does it. However, as you can see in the class declaration, there is one implementation detail that is visible to the user: the concrete data representation of our ADT that is listed in the private part. However, the data representation is still considered hidden information in the sense that the compiler prohibits client code from accessing the data directly. |
|
|
|
|
|
|
|
|
The specification (.h) file for the TimeType class contains only the class declaration. The implementation file must provide the function definitions for all the class member functions. In the opening comments of the implementation file below, we document the file name as timetype.cpp. Your system may use a different file name suffix for source code files, perhaps .c, .C, or .cxx. |
|
|
|
|
|
|
|
|
We recommend that you first skim the C++ code below, not being too concerned about the new language features such as prefixing the name of each function with the symbols |
|
|
|
|
|
|
|
|
Immediately following the program code, we explain the new features. |
|
|
|
|
|
|
|
|
//******************************************************************
// IMPLEMENTATION FILE (timetype.cpp)
// This file implements the TimeType member functions
//******************************************************************
#include timetype.h
#include <iostream.h>
// Private members of class:
// int hrs;
// int mins;
// int secs;
//******************************************************************
void TimeType::Set( /* in */ int hours,
/* in */ int minutes,
/* in */ int seconds ) |
|
|
|
|
|