Homework Five

Searching a Sorted File

Using the byte file of business faculty office records, create a program that can quickly find a faculty member's contact information. Since the data is sorted by Last Name, we will, of course, search by Last Name.

In case you don't still have the data sorted by last name, you can copy the file "faculty_sorted.dat" from Dannelly's home directory.

Don't forget that file begins with an integer that indicates the number of records in the file.

Use a binary search to search the file. In case you forgot how binary search works, according to wikipedia:

  min := 1;
  max := N; {array size: var A : array [1..N] of integer}
  repeat
    mid := min + (max - min) div 2;
    if x > A[mid] then
      min := mid + 1
    else 
      max := mid - 1;
  until (A[mid] = x) or (min > max);

Your program should prompt the user for a last name. If the name is found, print all the parts of that person's record. Be sure to make your output look nice. If the last name is not found, be sure to print a nice message.

Submit your code, either C or C++, as an attachment email to dannellys@winthrop.edu with the subject CSCI325 HW05. The assignment is due by 5:00pm on Friday March 11.