< previous page page_693 next page >

Page 693
    // Exit loop when item is found, perhaps as sentinel

    while (strcmp(item, list[index]) > 0)

            // Invariant (prior to test):
            //     item is not in list[0..index-1]

        index++;

    // Determine whether item was found prior to sentinel

    found = (index < length && strcmp(item, list[index]) == 0);
}

//******************************************************************

void CheckInStudents(
       /* in */    const String10 student[],      // List of students
       /* in */    int            length,         // Length of list
       /* inout */ Boolean        isPresent[] )   // Checkmark list

// Inputs student names from standard input,
// marking students present

// Precondition:
//     length <= MAX_LENGTH
//  && student[0..length-1] are in ascending order
//  && isPresent[0..length-1] are assigned
// Postcondition:
//     The user has been repeatedly prompted to enter student names
//  && For all i, where student[i] matches an input name,
//         isPresent[i] == TRUE
//  && For all input names not found in the student array,
//     an error message has been printed

{
    String10 stuName;       // Name of student who is checking in

    cout << "Enter last name: ";
    cin.get(stuName, 11);              // At most 10 chars plus '\0'
    cin.ignore(100, '\n');
    while (strcmp( stuName, END_DATA) != 0)
{
            // Invariant (prior to test):
            //     All students prior to current one
            //     have been checked in

 
< previous page page_693 next page >