/* Filename: recfind.cpp Author: Br. David Carlson Date: January 24, 1998 Last Revised: November 21, 2001 This program reads from the keyboard the data for a series of employees. (This data consists of each employee's first and last name, ID number, and wage rate.) The user is then allowed to repeatedly look up employee records by entering the user's last name and first name, with CTRL z entered to end lookups. (Substitute CTRL d in Linux, of course.) Tested with: Microsoft Visual C++ 6.0 Microsoft Visual C++ .NET g++ under Linux */ #include "emparray.h" /* Given: Nothing. Task: To prompt the user to enter the last and first name of an employee. Return: Employee Record containing these names, other fields unused. In the function name, return FailFlag if CTRL z was entered, OKFlag otherwise. */ int GetTarget(EmployeeType & Employee) { // Change to CTRL d for Linux: cout << endl << "Enter last name of employee to find (CTRL z to quit): "; cin >> Employee.LastName; if (cin.fail()) return FailFlag; cout << "Enter first name of this employee: "; cin >> Employee.FirstName; if (cin.fail()) return FailFlag; return OKFlag; } /* Given: EmpArray Array of employee records, already in order. EmpCount Number of employee records in EmpArray. Task: To allow the user to do repeated lookups for the data on an employee by entering the person's name. Return: Nothing. */ void Lookups(EmpArrayType EmpArray, int EmpCount) { EmployeeType Employee; int Flag, Result; cout << endl << endl; Flag = GetTarget(Employee); while (Flag == OKFlag) { Result = BinarySearch(EmpArray, 0, EmpCount - 1, Employee); if (Result == -1) cout << "Could not find this employee" << endl; else PrintEmployee(EmpArray[Result]); Flag = GetTarget(Employee); } cout << endl << endl; } int main(void) { EmpArrayType EmpArray; int Flag, EmpCount; Flag = LoadArray(EmpArray, EmpCount); if (Flag == TooMuchDataFlag) cout << endl << endl << "The data would not fit in the array" << endl; else Lookups(EmpArray, EmpCount); return 0; }