美式足球的解决方案探讨
英文的,不好意思啊!可是我很认真的。想了很久。一部分已经出来,但是Background:
The passer rating (known as QB rating) is a formula for evaluating the performance of a quarterback in
football:
http://en.
From Wikipedia, here is the way to calculate it. First start by calculating a, b, c and d:
Where:
ATT = Number of passing attempts
COMP = Number of completions
YARDS = Passing yards
TD = Touchdown passes
INT = Interceptions
Then, the above calculations are used to complete the passer rating:
Technically, you have to make sure a,b,c and d stay in the range 0-2.375. If one is below/above that range,
you bring it back to either 0 or 2.375. I will not test with any values that require this step.
Problem:
Write a program that will read in a text file called QB.txt The file will consist of data in this order:
FirstName LastName Comp Att Yards TD Int
Something like:
Aaron Rodgers 343 502 4643 45 6
Calculate the QB Rating for the player and print the players “lastName, firstName” and then a space, then
the QB rating to one decimal. Something like:
Rodgers, Aaron 122.5
我的解决方案如下。请大家探讨。 感谢先!
*/
/**
**********************************************************************************************************
Program that will read in a text file called QB.txt The file will consist of data in this order:
FirstName LastName Comp Att Yards TD Int
Something like:
Aaron Rodgers 343 502 4643 45 6
Calculate the QB Rating for the player and print the players “lastName, firstName” and then a space, then
the QB rating to one decimal. Something like:
Rodgers, Aaron 122.5.
**********************************************************************************************************
**/
//Header file
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
int main()
{
//Declare input file stream variable
ifstream inData;
ofstream outData;
//Declare variables;
int ATT, COMP,YARDS, TD, INT;
double a,b,c,d;
double QB_rating;
string firstName;
string lastName;
inData.open("QB.txt");
outData.open ("QB_Rating.txt");
// get information from file input stream
inData >> firstName >> lastName ;
//getline (inData, firstName);
inData >> COMP >> ATT >> YARDS >> TD >> INT ;
setprecision(1);
a = (float(COMP / ATT) - 0.3 ) * 5;
b = (float(YARDS / ATT) -3 ) * 0.25;
c = (float(TD / ATT ) )* 20 ;
d = 2.375 -((float(INT / ATT) * 25 ));
//if a <0
//a=0;
//if a > 2.375
//a= 2.375;
// same as b,c,d
cout <<a <<","<< b <<","<<c<<","<< d<< endl;
QB_rating = ( a + b + c + d ) / 0.06 ;
outData << fixed << showpoint ;
outData << setprecision(1);
outData << "QB Rating " << endl;
inData >> firstName >> lastName ;
outData << "lastName,firstName" <<setfill(' ') << "QB Rating" <<endl;
outData << setw(8)<< lastName <<","<< firstName << " "<< right << QB_rating;
//outData << "123456789012345678901234" << endl;
inData.close();
outData.close();
return 0;
}