/****************************************************************
* (insert short description of program here)
*
* This program calculate calculates and displays a tennis match summary.
* Assume there are two players and all input is of the correct format.
*
* Input: The names of two players, the number of first and second serves
* for each player: total and won.
*
* Output: The percentage of first serves in for each player
* The percentage of winning the first serve
* The percentage of winning the second serve
* The number of total points won
*
* Processing:
* .......
*
* Author: Sean Smith, Student No. 220018979, March 2006
*
********************************************************************/
#include // for cin and cout
#include // for setw()
using namespace std;
// Initialise String Variables
string PlayerA;
string PlayerB;
// Initialise User Entered Variables
int PA1stServesIn;
int PA1stServesWon;
int PA2ndServesIn;
int PA2ndServesWon;
int PB1stServesIn;
int PB1stServesWon;
int PB2ndServesIn;
int PB2ndServesWon;
// Initialise Calculated Variables
double PA1stWinPercent;
double PA2ndWinPercent;
double PB1stWinPercent;
double PB2ndWinPercent;
int PA1stServePercent;
int PB1stServePercent;
int PATotalPoints;
int PBTotalPoints;
int main()
{
// Prompt for PlayerA's name
cout << "\n\nPlease enter the first players name: ";
cin >> PlayerA;
// Prompt for PlayerB's name
cout << "Please enter the second players name: ";
cin >> PlayerB;
// Prompt for the number of 1st serves that PlayerA got in
cout << "\nPlease enter the number of 1st Serves that " << PlayerA << " got in: ";
cin >> PA1stServesIn;
// Promt for the number of 1st serves that PlayerA won
cout << "Please enter the number of points " << PlayerA << " won off their 1st serve (must be <= " << PA1stServesIn << "): ";
cin >> PA1stServesWon;
// Prompt for the number of 2nd serves that PlayerA got in
cout << "Please enter the number of 2nd Serves that " << PlayerA << " got in: ";
cin >> PA2ndServesIn;
// Prompt for the number of 2nd serves PlayerA won
cout << "Please enter the number of points " << PlayerA << " won off their 2nd serve (must be <= " << PA2ndServesIn << "): ";
cin >> PA2ndServesWon;
// Store the number of 1st serves and the number of 2nd serves won in PATotalPoints
PATotalPoints = PA1stServesWon + PA2ndServesWon;
// Calculate 1st Serve win %age
PA1stWinPercent = (PA1stServesWon * 100) / PA1stServesIn;
// Calculate 2nd Serve win %age
PA2ndWinPercent = (PA2ndServesWon * 100) / PA2ndServesIn;
// Calculate the Percentage of 1st Serves PlayerA got in
PA1stServePercent = (PA1stServesIn * 100) / (PA1stServesIn + PA2ndServesIn);
// Prompt for the number of 1st serves that PlayerB got in
cout << "\nPlease enter the number of 1st Serves that " << PlayerB << " got in: ";
cin >> PB1stServesIn;
// Promt for the number of 1st serves that PlayerB won
cout << "Please enter the number of points " << PlayerB << " won off their 1st serve (must be <= " << PB1stServesIn << "): ";
cin >> PB1stServesWon;
// Prompt for the number of 2nd serves that PlayerB got in
cout << "Please enter the number of 2nd Serves that " << PlayerB << " got in: ";
cin >> PB2ndServesIn;
// Prompt for the number of 2nd serves PlayerA won
cout << "Please enter the number of points " << PlayerB << " won off their 2nd serve (must be <= " << PB2ndServesIn << "): ";
cin >> PB2ndServesWon;
// Store the number of 1st serves and the number of 2nd serves won in PBTotalPoints
PBTotalPoints = PB1stServesWon + PB2ndServesWon;
// Caclulate 1st Serve win %age
PB1stWinPercent = (PB1stServesWon * 100) / PB1stServesIn;
// Caclulate 2nd Serve win %age
PB2ndWinPercent = (PB2ndServesWon * 100) / PB2ndServesIn;
// Calculate the Percentage of 1st Serves PlayerB got in
PB1stServePercent = (PB1stServesIn * 100) / (PB1stServesIn + PB2ndServesIn);
// Displays the Match Summary
cout << "\n\n----------------------------------------------------------------\n"
<< setw(22) << "Match Summary" << setw(17) << PlayerA << setw(17) << PlayerB
<< "\n----------------------------------------------------------------\n"
<< setw(22) << "1st Serve %" << setw(16) << PA1stServePercent << "%" << setw(16) << PB1stServePercent << "%" << endl
<< "Winning % of 1st Serve" << setw(4) << PA1stServesWon << " of" << setw(4) << PA1stServesIn << " = " << setw(2) << PA1stWinPercent << "%"
<< setw(4) << PB1stServesWon << " of" << setw(4) << PB1stServesIn << " = " << setw(2) << PB1stWinPercent << "%" << endl
<< "Winning % of 2nd Serve" << setw(4) << PA2ndServesWon << " of" << setw(4) << PA2ndServesIn << " = " << setw(2) << PA2ndWinPercent << "%"
<< setw(4) << PB2ndServesWon << " of" << setw(4) << PB2ndServesIn << " = " << setw(2) << PB2ndWinPercent << "%" << endl;
} // of main