|
|
|
|
|
|
|
void SelSort();
// Postcondition:
// List is in ascending order of employee last name
void PrintAll();
// Postcondition:
// All employee records have been written to
// standard output
RecordList();
// Postcondition:
// Empty list created
~RecordList();
// Postcondition:
// List destroyed
private:
PersonPtr ptrList[MAX_EMPL];
int length;
};
#endif |
|
|
|
|
|
|
|
|
Now we are ready to implement the RecordList member functions. We begin with the class constructor, whose sole task is to initialize the private variable length to zero. |
|
|
|
|
|
|
|
|
The class constructor RecordList () |
|
|
|
|
|
|
|
|
To implement the ReadAll member function, we use a loop that repeatedly does the following: allocates a dynamic PersonnelData struct, reads an employee record into that struct, and stores the pointer to that struct into the next unused element of the ptrList array. We must keep in mind that we might need as many as 1000 dynamic structs on the free store. When allocating large data structures dynamically, it is good to get into the habit of checking each allocation attempt to see if it was successful. Remember that the C++ new operator returns the null pointer instead of a pointer to dynamic data if the allocation failed. In the ReadAll function, if the allocation attempt fails, we report this fact to the caller through a Boolean parameter outOfMem. |
|
|
|
|
|