< previous page page_947 next page >

Page 947
called, all 500 TimeCard objects in the private list array are first constructed. These objects are constructed via implicit calls to the TimeCard class's default constructor. (Recall from Chapter 15 that an array of class objects is constructed using the class's default constructor, not a parameterized constructor.) After the list array elements are constructed, there is nothing left to do but to set the private variable length equal to zero:
TimeCardList::TimeCardList()

// Postcondition:
//     Each element of list array has an ID number of 0
//     and a time of 0:0:0 (via implicit call to each array
//     element's default constructor)
//  && length == 0

{
    length = 0;
}
To implement the ReadAll member function, we use a loop that reads each employee's data (ID number and hours, minutes, and seconds of the punch-in time) and stores the data into the next unused element of the list array. The loop terminates either when end-of-file occurs or when the length of the array reaches MAX_LENGTH. After exiting the loop, we are to print a warning message if more data exist in the file (that is, if end-of-file has not occurred).
ReadAll (Inout: inFile)
Read idNum, hours, minutes, seconds from inFile
WHILE NOT EOF on inFile AND length < MAX_LENGTH
   list[length].SetID(idNum)
   list[length].Punch(hours, minutes, seconds)
   Increment length by 1
   Read idNum, hours, minutes, seconds from inFile
IF NOT EOF on inFile
   Print warning that remaining time cards will be ignored

The implementation of the SelSort member function has to be slightly different from the one we developed in Chapter 12. Remember that SelSort finds the minimum value in the list and swaps it with the value in the first place in the list. Then the next smallest value in the list is swapped with the value in the second place. This process continues until all the values are in

 
< previous page page_947 next page >