|
|
|
|
|
|
|
// Postcondition:
// Class object is constructed
// && Time is set according to the incoming parameters
Time();
// Postcondition:
// Class object is constructed && Time is 0:0:0
private:
int hrs;
int mins;
int secs;
};
#endif |
|
|
|
|
|
|
|
|
(We surround the specification file with the preprocessor directives |
|
|
|
|
|
|
|
|
#ifndef TIME_H
#define TIME_H
.
.
.
#endif |
|
|
|
|
|
|
|
|
to prevent multiple inclusion of the Time class declaration in cases where a new class is created from Time by inheritance or composition. Later in the case study, we discuss this issue further. Meanwhile, you may want to review the Matters of Style box entitled Avoiding Multiple Inclusion of Header Files in Chapter 15.) |
|
|
|
|
|
|
|
|
You have already seen the implementations of the Time class member functions. They are the same as in the TimeType class of Chapter 15. |
|
|
|
|
|
|
|
|
By declaring a time stamp object to be of type Time, we can simply implement our time stamp operations as calls to the Time class member functions: |
|
|
|
|
|
|
|
|
Time timeStamp;
timeStamp.Set(hours, minutes, seconds);
timeStamp .Write(); |
|
|
|
|
|
|
|
|
Notice that the abstract operations we listed for a time stamp do not include an increment operation. Should we rewrite the Time class to eliminate the Increment function? No. Wherever possible, we want to reuse existing code. Let's use the Time class as it exists. The presence of the Increment function does no harm. We simply have no need to invoke it on behalf of a time stamp object. |
|
|
|
|
|