Question
This is a program in C++. Please help me out. The Dubuque Table Tennis Club wants a prototype program to process the scores of a
This is a program in C++. Please help me out.
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!
FINAL NOTE: You must adhere to the group requirements in: K:\Courses\CSSE\CourseFiles\CS1430\GroupReuirements.txt
In particular note the following requirement for the File Comment block and the -3 penalty for non-compliance:
Both persons in the group must do their fair share of work for the program. The header block at the top must contain each person's estimate of what percent each member contributed to the completion of the program. The percentages must add up to one hundred. For example:
Sally Smith: Sally - 60%, J Jacobs - 40%
John Jacobs: Sally S - 50%, John - 50%
Expect to lose up to 3 points on the program if this is not done.
Students not doing their share can expect their grade lowered.
If there are significant differences in what is reported (estimated), the instructor can call in the group to discuss.
Excessive collaboration may result in a 0 on the assignment for all students involved. Repeated instances may result in failing the course.
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 programming ground rules.
E. You must follow the formatting of the sample I/O below.
F. You must thoroughly test your program.
G. 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)
H. To get credit for the assignment, your solution must minimally work on Test Case # 1 below.
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.
Input for Run 1:
11
9
7
11
11
8
11
9
5
11
6
11
11
9
11
9
11
9
11
7
11
5
11
8
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
Winner is player C.
Input for Test Run 2:
-4
-5
4
-8
8
5
5
6
11
6
11
6
11
10
13
9
13
10
11
6
11
6
11
6
11
6
11
6
11
5
11
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
There is no clear winner.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started