< previous page page_1018 next page >

Page 1018
If we run the program and find too many or too few employee records printed out, or if the records are not in alphabetical order, the problem lies in the record list objectthe object responsible for reading the file, sorting, and printing. Using a hand trace, debug output statements, or the system debugger, we should check the RecordList member functions in the following order: ReadAll (to verify that the file data was read into the list correctly), SelSort (to confirm that the records are ordered by employee last name), then PrintAll (to ensure that all records are output properly).
After the program works correctly for the file of test data, we should also run the program against the following files: a nonexistent file and an empty file. With a nonexistent file, the program should halt after the OpenForInput function prints its error message. With an empty file, the program should terminate successfully but produce no output at all. (Look at the loops in the ReadAll, SelSort, and PrintAll functions to see why.)
Are we required to test the program with a file of more than 1000 employee records? No. Clearly, the program would misbehave if the index into the ptrList array exceeds 999. However, our program correctly satisfies the problem definition, which states a precondition for the entire programnamely, that the input file contains at most 1000 records. The user of the program must be informed of this precondition and is expected to comply. If the problem definition were changed to eliminate this precondition, then, of course, we would have to modify the program to deal with an input file that is too long.
One final remark: Regarding the SelSort function, what we have tested is that the program correctly sorts the data using pointers to dynamic variables of type PersonnelData. But the output may still be slightly wrong. Because SelSort compares the strings that make up the last names, it is ordering the names according to the machine's particular character set. As we mentioned in Chapter 12, such comparisons can lead to problems when uppercase and lowercase characters are mixed. For example, in the ASCII set. Macartney would come after MacDonald. Case Study Follow-Up Exercise 1 asks you to modify SelSort so that it orders names regardless of the case of the individual characters.
Problem-Solving Case Study Dynamic Arrays
1018-01.gif
Problem: In Chapter 15, Programming Warm-Up Exercise 10 described a safe array class (intArray) that prevents array indices from going out of bounds. The public member functions were: a class constructor, to create an array of up to MAX_SIZE elements and initialize all elements to zero; a Store function, to store a value into a particular array element; and a ValueAt

 
< previous page page_1018 next page >