< previous page page_946 next page >

Page 946
class TimeCardList
{
public:
    void ReadAll( /* inout */ ifstream& inFile );
        // Precondition:
        //     inFile has been opened for input
        // Postcondition:
        //     List contains at most MAX_LENGTH employee time cards
        //     as read from inFile. (Excess time cards are ignored
        //     and a warning message is printed)

    void SelSort();
        // Postcondition:
        //     List components are in ascending order of employee ID

    void BinSearch( /* in */  long      idNum,
                    /* out */ TimeCard& card,
                    /* out */ Boolean&  found ) const;
        // Precondition:
        //     List components are in ascending order of employee ID
        //  && idNum is assigned
        // Postcondition:
        //     IF time card for employee idNum is in list
        //         found == TRUE  && card == time card for idNum
        //     ELSE
        //         found == FALSE  && value of card is undefined

    TimeCardList();
        // Postcondition:
        //     Empty list created
private:
    TimeCard list[MAX_LENGTH];
    int      length;
};
#endif
The BinSearch function is a little different from the one we presented in Chapter 12. There, we returned the index of the array element where the item was found. Here, an array index would be useless to a client of TimeCardList. The array of time cards is encapsulated within the private part of the class and is inaccessible to clients. This version of BinSearch, therefore, returns the entire time card to the client.
Now we implement the TimeCardList member functions. Let's begin with the class constructor. Remember that when a class X is composed of objects of other classes, the constructors for those objects are executed before the body of X's constructor is executed. When the TimeCardList constructor is

 
< previous page page_946 next page >