Question
Instructions Write a C++ program which calculates and displays a baseball player's batting average and proficiency. There are an unknown number of players. For any
Instructions
Write a C++ 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.
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, 1 for 3, 1 for 4
-Im Ina Slump: 1 for 4, 0 for 3, 1 for 5, 1 for 4
Earn 5 extra credit points by "referencing" the batting averages and proficiencies back to main using reference variables instead of the return type.
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