< previous page page_696 next page >

Page 696
// Prints the names of those taking the exam, then the names
// of those who are absent

// Precondition:
//     length <= MAX_LENGTH
//  && student[0..length-1] are assigned
//  && isPresent[0..length-1] are assigned
// Postcondition:
//     For every i such that isPresent[i] == TRUE,
//         student[i] has been printed
//     Then, for every i such that isPresent[i] == FALSE,
//         student[i] has been printed

{
    int count;      // Loop control variable

    cout << end1 << "The following students are taking the exam."
        << end1;
    for (count = 0; count < length; count++)

            // Invariant (prior to test):
            //     For all i, where 0 <= i <= count - 1,
            //        IF isPresent[i]
            //            student[i] has been printed
            //  && 0 <= count <= length

        if (isPresent[count])
            cout << student[count] << endl;

    cout << end1 << "The following students have missed the exam."
         << end1;
    for (count = 0; count < length; count++)

            // Invariant (prior to test):
            //     For all i, where 0 <= i <= count - 1,
            //        IF NOT isPresent[i]
            //            student[i] has been printed
            //  && 0 <= count <= length

        if ( !isPresent[count] )
            cout << student[count] << end1;
}
Testing: The program must be tested with names that are more than ten characters, exactly ten characters, and less than ten characters. Names read from the keyboard must be spelled incorrectly as well as correctly. The following data was used.

 
< previous page page_696 next page >