< previous page page_948 next page >

Page 948
order. The location in this algorithm that we must change is where the minimum value is determined. Instead of comparing two time cards in the list (which doesn't make any sense), we compare the ID numbers on the time cards. To inspect the ID number on a time card, we use the observer function IDPart provided by the TimeCard class. The statement that did the comparison in the original SelSort function must be changed from
if (list[placeCount] < list[minIndex])
to
if (list[placeCount].IDPart() < list[minIndex].IDPart())
We must make a similar change in the BinSearch function. The original version in Chapter 12 compared the search item with list components directly. Here, we cannot compare the search item (an ID number of type long) with a list component (an object of type TimeCard). Again, we must use the IDPart observer function to inspect the ID number on a time card.
Below is the implementation file for the TimeCardList class.
//******************************************************************
// IMPLEMENTATION FILE (tclist.cpp)
// This file implements the TimeCardList class member functions.
// List representation: an array of TimeCard objects and an
// integer variable giving the current length of the list
//******************************************************************
#include tclist.h
#include <iostream.h>

// Private members of class:
//    TimeCard list[MAX_LENGTH];    Array of TimeCard objects
//    int      length;              Current length of list

//******************************************************************

TimeCardList::TimeCardList()

// Default constructor

// 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)

 
< previous page page_948 next page >