In c++ You are fully aware that performance of a running back in football is jud
ID: 3833440 • Letter: I
Question
In c++
You are fully aware that performance of a running back in football is judged based on following factors:
Average number of yards ran per game in the season.
Total number of yards ran in a season.
Average number of yards ran per carry.
Fumbles (Reduce the performance).
Touch downs (increase the performance index).
For the sake of simplicity, we will only consider average rushing yards per game as a performance and an index to award bonus.
In this program we will compute the bonus a running back would get based on the rounded average number of yards they ran per game in a season. The bonus schedule is as follows:
Average Yards Rushing
Bonus
> 200
$50,000.00
<= 200 but > 150
$30,000.00
<= 150 but > 100
$20,000.00
<= 100 but > 50
$10,000.00
<= 50
$0.00
The program reads a file that has running back data stored in it. The structure of each record is like the one below:
Joe Neddy 250 200 190 201 195 -1
The file stores first and last name of the running back followed by rushing yards in various games (number of games may vary for various players. All players need not have same number of games).
The last value which is a negative value is a sentinel value for rushing yards.
Some players may be in the file but they may not have any data on the rushing yards. For example the file may contain a record such as below:
Tim Toms -6
The program will compute and print the sum of yards ran in all games, number of games, and average yards ran per game, rounded average yards per game. Finally program will compute and print the bonus the running back has earned for the season. The output is done to file as well as to console. Finally program prints number of players in the file and also the sum of bonuses awarded to all players.
One style of output is shown below. However, if a better style can be developed, that would be welcome.
******************************************************************
Joe Neddy, your rushing yards in various games are: 250 200 190 201 195
The total rushing yards for all games = 1036
Your average rushing yards in 5 games is: 207.20
Your rounded average rushing yards is = 207
Your bonus = $ 50000.00
At the end the program should print the number of players in the data file and total dollars awarded in bonus to all players.
Notes: For each of below software violations, 5% of the points will be taken off for each violation 1 to 5. Amount for others is listed.
If double data type is not used for currency data.
If currency data in dollars is not formatted to two decimal points before outputting.
If int or other integral data types is not used for whole numbers in the file.
If int or other integral data types is not used for those variables which are populated by arithmetical operations on integral type data only.
If sentinel control loop is not used for the data that has sentinel value or data in file shows a sentinel value.
If program has runtime or logical error (10% off for each runtime error).
Compile error: 3 points off.
Average Yards Rushing
Bonus
> 200
$50,000.00
<= 200 but > 150
$30,000.00
<= 150 but > 100
$20,000.00
<= 100 but > 50
$10,000.00
<= 50
$0.00
Explanation / Answer
#include<iostream.h>
#include<vector>
#include<string>
#include<math.h>
using namespace std;
struct playerdata{
string first;
string last;
vector<int> yards;
};
bool is_number(string s)
{
for (int i = 0; i<s.length(); i++){
if (s.at(i) == '-')
continue;
if ( !('0' <= s.at(i) && s.at(i) <= '9'))
return false;
}
return true;
}
double calBonus(float avg){
double bonus;
if (avg > 200)
bonus = 50000.00;
if (avg > 150 && avg <= 200)
bonus = 30000.00;
if (avg > 100 && avg <= 150)
bonus = 20000.00;
if (avg > 50 && avg <= 100)
bonus = 10000.00;
if (avg < 50 )
bonus = 0.00;
return bonus;
}
void main(){
ifstream infile;
infile.open("input.txt");
string data;
struct playerdata pdata;
vector<playerdata> playerlist;
int count, sum;
float avg;
count = -1;
double totalbonus;
while (infile << data){
count++;
if (!is_number(data) && count == 0)
pdata.first = data;
if (!is_number(data) && count == 1)
pdata.last = data;
if (is_number(data) && stoi(data) > 0 )
pdata.yards.push_back(stoi(data));
if (is_number(data) && stoi(data) < 0){
count = -1;
playerlist.push_back(pdata);
}
}
infile.close();
totalbonus = 0;
for (int i = 0; i < playerlist.size(); i++){
cout << playerlist.at(i).first << " " << playerlist.at(i).last
<< " your rushing yards in various games are:" ;
sum = 0;
for (int j = 0; j < playerlist.at(i).yards.size(); j++){
cout << playerlist.at(i).yards.at(j) << " ";
sum = sum + playerlist.at(i).yards.at(j);
}
cout << endl;
avg = sum / playerlist.at(i).yards.size();
cout << "Your average rushing yards in " << playerlist.at(i).yards.size() << "games is:"
<< setprecision(2) << avg << endl;
cout << "Your rounded average rushing yards is " << setprecision(0) << round(avg) << endl;
cout << "Your bonus =" << "$" << setprecision(2) << calBonus(avg) << endl;
totalbonus = totalbonus + calBonus(avg);
}
cout << "Total players:" << playerlist.size() << endl;
cout << "Total Bonus awarded:" << setprecision(2) << totalbonus << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.