Sei sulla pagina 1di 2

Question 1

The cost to become a member of a fitness center is as follows: (a) Senior citizens
discount is 30%, (b) If membership is bought and paid for 12 or more months, the
discount is 15%, (c) If more than five personal training sessions are bought and
paid for, the discount on each session is 20%.
Write a menu-driven program that determines the cost of a new membership. Your
program must contain a function that displays the general information about the
fitness center and its charges; a function to read all of the necessary information to
determine the membership cost; and a function to determine the membership cost.
Use appropriate parameters to pass information in and out of a function. Do not use
global variables.
Question 2
Write a program that calculates the average of a group of test scores, where the
lowest score in the group is dropped (not to be counted). It should use the following
functions:
getScore() function to read a test score from the user, validate it, and return it to
the main() function. The program should call this function five times to read five
inputs. calcAverage() function to calculate and return the average of the four
highest scores. findLowest() function to find and return the lowest of the five
scores passed to it. This function should be called by calcAverage() function to
determine which score to be dropped.
The program should then display the average test score.
Question 3
Write a program that lets the user play the game of Rock, Paper, and Scissors,
against the computer. The program should work as follows:
When the program begins, a random number in the range of 1 through 3 is
generated. If the number is 1, then the computer has chosen rock. If the number is
2, then the computer has chosen paper and if the number is 3, then the computer
has chosen scissors. Do not display the computers choice yet. This should be done
in a function called getComputerInput(). The random number is returned to main().
Next, get the user to input his/her choice of rock, paper, or scissors through the
keyboard. You can use a menu if you prefer. This should be done in another function
called getPlayerInput() and the users choice should be returned to main(). Pass
both computers choice and players choice to another function called getWinner().
The function should determine and return the winner to main(). If there is no
winner, the function should return a suitable value to indicate this. A winner is
selected according to the following rules: If one player chooses rock and the
other player chooses scissors, then rock wins. (The rock smashes the scissors) If
one player chooses scissors and the other player chooses paper, then scissors wins.
(Scissors cut the paper) If one player chooses paper and the other player chooses
rock, then the paper wins. (Paper wraps rock) If both players make the same
choice, there is no winner.

The main() function should display the computers choice and declare the winner.
If there is no winner, the game must be played again to determine the winner.

Potrebbero piacerti anche