|
|
|
|
|
|
|
// Precondition:
// length <= MAX_FRIENDS
// && addressBook[0..length-1] are assigned
// Postcondition:
// Contents of addressBook[0..length-1] have been output
// to friendFile
{
int counter; // Loop counter
for (counter = 0; counter < length; counter++)
{
// Invariant (prior to test):
// Contents of addressBook[0..counter-1] have
// been output
// && 0 <= counter <= length
friendFile << addressBook[counter].firstName <<
<< addressBook[counter].lastName << endl;
friendFile << ( << addressBook[counter].areaCode << )
<< addressBook[counter].phoneNumber << endl;
friendFile << setw(2) << addressBook[counter].month << /
<< setw(2) << addressBook[counter].day << /
<< setw(4) < addressBook[counter].year << endl;
friendFile << endl;
}
} |
|
|
|
|
|
|
|
|
Testing: This is an interactive program in which the user has a great deal of control. The user is prompted to enter data, then is asked if the data have been entered correctly. If the user indicates that there has been an error, the data are not saved. After the information about a person is entered, the user is asked whether he or she wishes to continue. |
|
|
|
|
|
|
|
|
In testing this program, each of the two options must be selected by the user at least once. When testing an interactive program, you may be tempted to sit down and just enter data randomly. However, if you don't keep a record of the data entered, the saved file will show only the correct entries. You won't know whether or not the sections of code that allow the program to ignore an incorrect entry were tested. |
|
|
|
|
|
|
|
|
Another thing to be tested is the alternate way in which the main reading loop can terminate: the address book becomes full. As MAX_FRIENDS is defined to be 150, you don't want to sit at the keyboard and type 150 entries to watch it become full! What you can do is comment out the const declaration by preceding it with //. Then insert a new declaration defining |
|
|
|
|
|