< previous page page_942 next page >

Page 942
    Time TimePart() const;
        // Postcondition:
        //     Function value == time stamp on the time card

    void Print() const;
        // Postcondition:
        //     Time card has been output in the form
        //       ID: 235658 Time: 08:14:25

    TimeCard();
        // Postcondition:
        //     Class object is constructed with an ID number of 0
        //     and a time of 0:0:0
private:
    long id;
    Time timeStamp;
};
#endif
The private part of this class declaration shows very clearly the composition relationship we proposed earliernamely, that a time card object is composed of an ID number object and a time stamp object.
To implement the abstract operations on a time stamp, we must implement the TimeCard class member functions. Earlier in the chapter, we showed how to implement the constructor, Punch, and Print functions, so we do not repeat the discussion here. Now we must implement SetID, IDPart, and TimePart. These are easy. The body of SetID merely sets the private variable id equal to the incoming parameter, idNum:
id = idNum;
The body of IDPart needs only to return the current value of id, and the body of TimePart simply returns the current value of the private object timeStamp. Here is the implementation file containing the definitions of all the TimeCard member functions:
//******************************************************************
// IMPLEMENTATION FILE (timecard.cpp)
// This file implements the TimeCard class member functions
//******************************************************************
#include timecard.h
#include <iostream.h>

 
< previous page page_942 next page >