|
|
|
|
|
|
|
// Precondition:
// masterFile has been successfully opened for output
// && masterList ends with a sentinel record
// Postcondition:
// Contents of masterList have been written to masterFile
{
int index = 0; // Array index
do
{
masterFile << masterList[index].lastName <<
<< masterList[index].firstName <<
<< masterList[index].phone.areaCode <<
<< masterList[index].phone.phoneNumber << endl;
index++;
// Invariant:
// masterList[0..index-1] have been written
// to masterFile
// && Sentinel record is not in masterList[0..index-2]
} while (strcmp(masterList[index-1].lastName, SENTINEL) != 0) ;
} |
|
|
|
|
|
|
|
|
Testing: Because we have three input files, there are several cases to test. |
|
|
|
|
|
|
|
|
4. file2 and file3 are empty. |
|
|
|
|
|
|
|
|
5. file1 and file3 are empty. |
|
|
|
|
|
|
|
|
6. file1 and file2 are empty. |
|
|
|
|
|
|
|
|
7. All three files are empty. |
|
|
|
|
|
|
|
|
8. All three files have values. |
|
|
|
|
|
|
|
|
There are data-dependent conditions that should be tested as well: |
|
|
|
|
|
|
|
|
1. The files should be tested with each one containing the name that comes first in the alphabet. |
|
|
|
|
|
|
|
|
2. The files should be tested with each pair containing duplicate names in the first position, an intermediate position, and the last position. |
|
|
|
|
|
|
|
|
3. The files should be tested with each one containing the name that comes last in the alphabet. |
|
|
|
|
|