I'm having trouble wrapping my head around this problem. Please help me get started.
Problem Description
The Dubuque Table Tennis Club wants a prototype program to process the scores of a 3-person round robin. The 3 players are designated as player A, player B and player C. In a round robin of 3 players, player A plays player B in a match of the best of 3 out of 5 games. Player B then plays player C, and finally player C plays player A.
A table tennis game is played such that the first player to 11 wins. However, the player must win by a least 2 points. So game scores of 11 to 0, 11 to 9, 12 to 10, and 21 to 19 are legitimate. Game scores of 4 to 1, 12 to 9, 8 to 5, and 10 to 8 are NOT legitimate. In addition, any negative scores should be immediately rejected. See the sample runs on exactly how to re-prompt the user for incorrect game scores.
The program is to print the winner of the round robin. The winner of the round robin is the person who either wins both their matches or if all three players have each won one match, the player with the better won-loss record. As one can see in Sample Run # 1 below, player A won 3
games and lost 4, player B won 4 games and lost 5, and player C won 5 games and lost 3. Player A has a winning percentage of (3.0 / (3 + 4)) which is about 42.9%, player B has a winning percentage of (4.0 / (4 + 5)) which is about 44.4%, and player C has a winning percentage of
(5.0 / (5 + 3)) which is 62.5%. So Player C is the winner of the round robin because Player C has the best winning percentage.
Lastly, note that there are scenarios in which there is NO clear winner solely based on number matches won and number of games won and lost. As in Sample Run # 2, each player won one match 3 wins to 0 losses and each finished the match with 3 games won and 3 games lost. When a scenario like this occurs, the program should print the following message:
There is no clear winner.
NOTE: For this program there is NO clear winner if each of the 3 players
wins one match and each player has the same number of wins.
NOTE: In an actual tournament for the "NO clear winner" case,
the tournament director would total number of points scored
by each player. THIS PROGRAM SHOULD NOT TOTAL POINTS SCORED!
The following additional requirements must be followed:
A. Your main function should adhere to the following pseudocode:
--- Pseudocode ----
Process one match of player A versus player B
Process one match of player B versus player C
Process one match of player C versus player A
Print the heading
Print the player results for player A
Print the player results for player B
Print the layer results for player C
if there is no clear winner then
write "There is no clear winner."
else
print winner
B. The above pseudocode suggests some functions.
Keep these functions single-minded, performing a focused task that can be well-named. You should design pseudocode for each of these functions.
All function bodies, including the body of main, should be NO more than 30 lines long, including braces, blank lines and comments.
C. You must NOT use arrays or structures.
D. You must follow the formatting of the sample I/O below.
E. You must thoroughly test your program.
F. You must use the following functions and you MUST add the documentation for the parameters to these functions. You will lose 2 points each for each function not used.
This function reads in a table tennis score and returns the value read if it is a legitimate score. A legitimate score
is any nonnegative value. The function continues to read
until a valid score is read issuing an error message if not valid.
params: TODO
int ReadScore( string prompt )
This function returns true if the two table tennis scores entered are legitimate according to the present USATT rules that stipulate the first player to 11 wins and must win by 2 points.
It returns false otherwise.
params: TODO
bool LegitScores(int score1, int score2 )
// This function reads in table tennis scores for one table
// tennis game until legitimate scores are entered and returns // the points scored via the parameters, score1 and score2.
// params: TODO
void ProcessOneGame(int& score1, int& score2 )
// This function processes a table tennis match of best 3 of 5
// games to win a match. Games are processed until the match is // won; the match is won when a player has won 3 games. Each
// players, wins and losses [player1GamesWon, player1GamesLoss, // player2GamesWon, player2GamesLoss] are updated appropriately. // Finally, once the winner of the match is determined, the
// appropriate player's match total is updated [player1Matches, // player2Matches].
// params: TODO
void ProcessOneMatch(int& player1Matches, int& player1GamesWon,
int& player1GamesLoss, int& player2Matches,
int& player2GamesWon,int& player2GamesLoss)
{
}
// This function returns true if there is a tie (no clear
// winner) based on the games won and matches won. It returns // false otherwise.
// params: TODO
bool NoClearWinner(int Aswins, int Asmatches,
int Bswins, int Bsmatches,
int Cswins)
// This function displays a players individual results
// params: TODO
void PrintPlayerResults( char playerLetter, int matchesWon,
int gamesWon, int gamesLost)
I. Hints
1. Function ProcessOneMatch will loop until there is a winner, i.e. the number of wins for one of the two players has reached 3.
2. Function ProcessOneMatch will call function ProcessOneGame in the loop.
3. Function ProcessOneGame will call ReadScore several times.
ProcessOneGame should use LegitScores to control it's loop.
4. Get function ProcessOneGame to work first; once you are satisfied it works then you can work on ProcessOneMatch.
------------------------------------------------------------------------
Sample I/O
Below are two sample runs.
They do NOT cover all cases.
The output for Test Run 1:
Enter first score: 11
Enter second score: 9
Enter first score: 7
Enter second score: 11
Enter first score: 11
Enter second score: 8
Enter first score: 11
Enter second score: 9
Enter first score: 5
Enter second score: 11
Enter first score: 6
Enter second score: 11
Enter first score: 11
Enter second score: 9
Enter first score: 11
Enter second score: 9
Enter first score: 11
Enter second score: 9
Enter first score: 11
Enter second score: 7
Enter first score: 11
Enter second score: 5
Enter first score: 11
Enter second score: 8
Round Robin Results
Player Matches Games Games
Won Won Lost
------ ------- ----- -----
A 1 3 4
B 1 4 5
C 1 5 3
Output for Run 2:
Enter first score: -4
Incorrect score : -4 entered.
Make sure score is nonnegative.
Enter first score: -5
Incorrect score : -5 entered.
Make sure score is nonnegative.
Enter first score: 4
Enter second score: -8
Incorrect score : -8 entered.
Make sure score is nonnegative.
Enter second score: 8
Scores given are not legitimate.
Enter first score: 5
Enter second score: 5
Scores given are not legitimate.
Enter first score: 6
Enter second score: 11
Enter first score: 6
Enter second score: 11
Enter first score: 6
Enter second score: 11
Enter first score: 10
Enter second score: 13
Scores given are not legitimate.
Enter first score: 9
Enter second score: 13
Scores given are not legitimate.
Enter first score: 10
Enter second score: 11
Scores given are not legitimate.
Enter first score: 6
Enter second score: 11
Enter first score: 6
Enter second score: 11
Enter first score: 6
Enter second score: 11
Enter first score: 6
Enter second score: 11
Enter first score: 6
Enter second score: 11
Enter first score: 5
Enter second score: 11
Round Robin Results
Player Matches Games Games
Won Won Lost
------ ------- ----- -----
A 1 3 3
B 1 3 3
C 1 3 3