Description:
Write a program which calculates and displays a baseball player's batting average and proficiency. There are an unknown number of players.
For any game in which a player participates, his batting average is calculated by dividing his number of hits by his number of at-bats. So if a player had 1 hit in 3 at-bats (we say he was "1 for 3"), his batting average would be .333. If a player was 3 for 4, his batting average for the game would be .750. And if a player played in ten games in which he was 9 for 36, his batting average for the ten games would be .250 (batting averages are always expressed in 3 decimals).
In main, repeatedly have the user enter a player's full name, have the program call the two functions described below, and display the player's batting average and proficiency, until all players' are processed.
Requirements:
The program will have two functions:
1) this function will receive a player's name into its parameter list; then the function will repeatedly process each of the player's games, using the player's name to prompt the user for the player's hits and at-bats for each game, for any number of games, i.e., each player may have played in a different number of games (you may not ask the user to enter the number of games). Validate that for each game, the hits and at-bats are zero or greater, and the hits must not exceed the at-bats (hits and at_bats are data type "int"). Summarize the hits and at-bats for each game, then calculate the batting average for the player and return it to main.
2) in main, the call to this function will pass it a player's batting average; the function will then determine the player's batting proficiency based on the chart below. The function will return the batting proficiency to main.
Batting Average Range Proficiency
.000 less than .250 Minor Leaguer
.250 less than .300 All Star
.300 less than .400 Hall of Famer
over .400 King of Baseball
In main the program will display the player's name, batting average, and proficiency in a user-friendly manner. Display the batting averages to 3 decimal points (don't worry about the leading zero).
Provide 3 screen prints by entering the following data for these players (name; hits & at-bats):
-Will E. Maize; 1 for 3, 2 for 4, 0 for 0, 2 for 3, 1 for 4, 3 for 5
-Jo Dim Magico; 1 for 4, 2 for 3, 3 for 4
-Im Ina Slump: 1 for 4, 0 for 3, 1 for 5, 1 for 4
I've been out of town at a funeral and i am really struggling with completing this assignment could someone help me
this is what i have so far but i need to input in that it chooses a batting average proficiency based on their average but not sure how to implement
(BattingAverage>.000 && BattingAverage<.250) return "Minor Leaguer"
(BattingAverage>.250 && BattingAverage<.300) return "All Star"
(BattingAverage>.300 && BattingAverage<.350) return "Hall of Famer"
(BattingAverage>.350 && BattingAverage<.400) return "King of Baseball"
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
|
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
float BattingAverage(int hits, int bats);
int main()
{
const int MaximumPLAYERS = 10;
string players[MaximumPLAYERS];
int hits[MaximumPLAYERS];
int atBats[MaximumPLAYERS];
float batAverage[MaximumPLAYERS];
int PlayerIndex = 0;
int battingIndex = 0;
char again;
do
{
cout << "Enter Player #" << PlayerIndex + 1 << " stats:" << endl;
cout << "Name: ";
cin >> players[PlayerIndex];
cout << "Hits: ";
cin >> hits[PlayerIndex];
while (hits[PlayerIndex] <= 0) {
cout << "Reenter Hits : ";
cin >> hits[PlayerIndex];
}
cout << "Total At Bats: ";
cin >> atBats[PlayerIndex];
while (atBats[PlayerIndex] < hits[PlayerIndex]) {
cout << "Reenter At Bats : ";
cin >> atBats[PlayerIndex];
}
PlayerIndex++;
if (PlayerIndex < MaximumPLAYERS) {
cout << "Enter another player (y / n) : ";
cin >> again;
again = tolower(again);
}
cout << endl;
} while (again == 'y' && PlayerIndex < MaximumPLAYERS);
cout << endl;
cout << "PLAYER AVG" << endl;
cout << "=================" << endl;
cout << left << fixed << setprecision(3);
for (int k = 0; k < PlayerIndex; k++)
{
batAverage[k] = BattingAverage(hits[k], atBats[k]);
cout << setw(12) << players[k];
cout << batAverage[k] << endl;
if (batAverage[k] > batAverage[battingIndex]) {
battingIndex = k;
}
}
cout << endl << "Batting champion: " << players[battingIndex] << ", " << batAverage[battingIndex] << " career average!" << endl;
return 0;
}
float BattingAverage(int hits, int bats)
{
float average = float (hits) / bats;
return average;
}
|