So, I have worked on most of the functions in this assignment. Please tell me if it looks right and help me start int main().
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.
Here is my pseudocode:
A. Your main function should adhere to the following 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
const int WSM = 11; //Short for WINNING_SCORE_MINIMUM
const int TWO = 2;
const int THREE = 3;
int main()
{
string prompt1= "Enter first score: ";
return 0;
}
//--------------------------------------------------------------
// 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: OUT
//--------------------------------------------------------------
int ReadScore(string prompt)
{
int scores; cout << prompt; cin >> scores;
for( ;scores < 0; cin>> scores)
{
cout << endl << "Invalid score: " << scores << endl << prompt;
}
return scores;
}
//--------------------------------------------------------------
// 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: (IN,IN)
//--------------------------------------------------------------
bool LegitScores(int score1, int score2)
{
if (score1 >= WSM || score2 >= WSM)
{
if ((score1 > WSM || score2 > WSM) && abs(score1 - score2) == TWO)
return 0;
}
else if (score1 == WSM || score2 == WSM)
return 0;
else if ((score1 > WSM || score2 > WSM) && (abs(score1 - score2) == 1))
return 1;
return 1;
}
//--------------------------------------------------------------
// 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: INOUT, INOUT, IN
//--------------------------------------------------------------
void ProcessOneGame(int& score1, int& score2, string prompt)
{
score1 = ReadScore(prompt);
score2 = ReadScore(prompt);
while (LegitScores(score1, score2) == false)
{
score1 = ReadScore(prompt);
score2 = ReadScore(prompt);
}
}
//--------------------------------------------------------------
// 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: OUT,INOUT,INOUT, OUT, INOUT, INOUT
//--------------------------------------------------------------
void ProcessOneMatch(int& player1Matches, int& player1GamesWon,
int& player1GamesLoss, int& player2Matches,
int& player2GamesWon, int& player2GamesLoss)
{//all the following integer variables are temporary and abbreviated
int w, x;
int p1gw = player1GamesWon = 0;
int p1gl = player1GamesLoss = 0;
int p2gw = player2GamesWon = 0;
int p2gl = player2GamesLoss = 0;
while (player1GamesWon < THREE && player2GamesWon < 3)
{
ProcessOneGame(w, x);
if (w < x)
{
player1GamesWon++;
player2GamesLoss++;
}
else
{
player1GamesLoss++;
player2GamesWon++;
}
}
if (player1GamesWon == THREE)
player1Matches++;
else
player2Matches++;
player1GamesWon += p1gw;
player1GamesLoss += p1gl;
player2GamesWon += p2gw;
player2GamesLoss += p2gl;
return;
}
//--------------------------------------------------------------
// 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)
{
return false;
}
//--------------------------------------------------------------
// This function displays a players individual results
// params: TODO
//--------------------------------------------------------------
void PrintPlayerResults(char playerLetter, int matchesWon,
int gamesWon, int gamesLost)
{
}
|