< previous page page_589 next page >

Page 589
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
You may assume that the number has at least one digit on either side of the decimal point.
4. The program that plays rock, paper, and scissors takes its input from two files. Rewrite the program so that it uses interactive input from two players. The main module should be as follows:
DO
 Get command
IF command is CONTINUE
Play game
ELSE IF command is PRINT_STATS
Print statistics
WHILE command isn't STOP

3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
command should be a variable of an enumeration type whose enumerators are CONTINUE, PRINT_STATS, and STOP. The statistics to be printed are the current game number, the current number of wins for the first player, and the current number of wins for the second player. The Get Command module should begin by asking if the players want to see the current statistics. If they do not, the first player should be prompted to enter a C to continue or an S to stop. If the first player wishes to continue, ask the second player; command should be CONTINUE if both players enter a C, and STOP otherwise. If both players wish to continue, the first player and then the second player should be prompted to enter a play.
Case Study Follow-Up
1. In the case study Finding the Area Under a Curve, it would be more efficient to go directly from midpoint to midpoint and not use the left edge of a rectangle at all. How would you change the program to use this approach?
2. What is the advantage of converting R, P, and S into values of an enumeration type in the Rock, Paper, Scissors case study?
3. Write the print functions for the BirthdayReminder program for a few of your friends and family.
4. Expand the BirthdayReminder program to read in a month and a date. The input data should be converted into a value in an enumeration type whose enumerators are FIRST_WEEK, SECOND_WEEK, THIRD_WEEK, and FOURTH_WEEK using the following formula:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Dates 1-7:   FIRST_WEEK
Dates 8-14:  SECOND_WEEK
Dates 15-21: THIRD_WEEK
Dates 22+:   FOURTH_WEEK
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Each monthly print function should take the week as a parameter and print the following message heading:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Reminders for the (first, second, third, fourth)week of (January) are:

 
< previous page page_589 next page >