< previous page page_809 next page >

Page 809
MAX_FRIENDS to be, say, 3. Now you can compile and run the program again, verifying that the loop terminates after three iterations. After this test, you can go back and remove the temporary const declaration and restore the original one by deleting the //.
Problem-Solving Case Study Campaigning for a Candidate
0809-01.gif
Problem: A friend is running for City Council. It's down to the wire, and we want to call all those people who showed an interest in our friend and remind them to vote on election day. We have three different lists of people we should call. We don't want to annoy people by calling them twiceor worse still, three timesso we decide to merge the three lists and remove any duplicates. Each list is already in alphabetical order by last name, and there are no duplicates within any one list. A dummy record with a last name of all Zs is appended at the end of each file.
Input: Three input files (file 1, file2, and file3), each containing a sequence of lines in the form
Jones Arthur 612 374-6715
A person's last name (maximum 15 characters with no blanks), first name (maximum 15 characters with no blanks), area code (integer), and phone number (8 characters) are separated by one or more blanks. The people's records are in alphabetical order by last name. A sentinel record containing all Zs for the last name signals the end of each file. The values on the rest of this line can be anything:
ZZZZZZZZZZZZZZZ A 111 111-1111
Output: The records from file1, file2, and file3 merged onto file masterFile, which should have the same form as the three input files.
Discussion: One of our problem-solving heuristics is to solve simpler problems first. Let's solve the problem for two lists, and then expand the solution to three lists.

 
< previous page page_809 next page >