|
|
|
|
|
|
|
ProcessName(student, length, stuName, isPresent);
cout << "Enter last name: ";
cin.get(stuName, 11);
cin.ignore(100, '\n');
}
}
//******************************************************************
void ProcessName(
/* in */ const String10 student[], // List of students
/* in */ int length, // Length of list
/* in */ const String10 stuName, // Input student name
/* inout */ Boolean isPresent[] ) // Check mark list
// Searches for stuName in the student array. If stuName
// is found, the corresponding position in the isPresent array
// is set to TRUE. Otherwise, an error message is printed
// Precondition:
// length <= MAX_LENGTH
// &&student[0..length-1] are in ascending order
// && stuName is assigned
// && isPresent[0..length-1] are assigned
// Postcondition:
// IF there is some i for which student[i] contains stuName
// isPresent[i] == TRUE
// ELSE
// An error message has been printed
{
int index; // Location of student name if found
Boolean found; // True if student is on roster
BinSearch(student, stuName, length, index, found);
if (found)
isPresent[index] = TRUE;
else
cout << "Name not on roste." << end1;
}
//******************************************************************
void BinSearch(
/* in */ const String10 list[], // List to be searched
/* in */ const String10 item, // Item to be found
/* in */ int length, // Length of list
/* out */ int& index, // Item location if found |
|
|
|
|
|