< previous page page_569 next page >

Page 569
An examination of the output shows it to be correct: player A did win six games, player B did win three games, and player A won the most games. This one set of test data is not enough to test the program completely. It should be run with test data where player B wins, where player A and player B tie, where fileA is longer than fileB, and where fileB is longer than fileA.
Problem-Solving case Study Birthday Reminder
0569-01.gif
Problem: Everyone has at least one friend who always remembers everyone's birthday. Each year when we receive appropriate greetings on our birthday from this friend, we promise to do better about remembering others' birthdays. Let's write a program that prints the names of those friends who have a birthday in a given month.
Input: A month entered from the keyboard, with first letter capitalized.
Output: The names (and birthdays) of all friends with a birthday in that month.
Discussion: If we were solving this problem by hand, we would turn our calendar to the month in question and list the names written there. That is exactly what our program does: it recognizes which month is being requested and calls a function that writes out the information for that month. The information for each month is represented as a series of output statements.
We represent the months as an enumeration type whose domain is the values JANUARY, FEBRUARY, MARCH, DECEMBER. Thus, we must convert the month as input in character form into this type. We can perform the conversion by checking just the first one, two, or three characters of the input string. February, September, October, November, and December have unique first characters. April, August, and January can be distinguished by their first two characters. June, July, March, and May require three characters to distinguish them.
Assumptions: None.

 
< previous page page_569 next page >