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 121 122 123 124 125 126 127 128 129 130 131 132
|
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;
string filename, line;
char teamABV[4], fullName[21];
float completions, attempts, yards, touchdowns, interceptions,
compPercent, ypAttempt, tdpAttempt, ipAttempt, qbRating;
int main()
{
cout << "This program will calculate the average passer rating based " << endl;
cout << "on data from a text file." << endl;
cout << "Please enter your full file's path." << endl;
cin >> filename;//Get file name for user input
ifstream qbinfo;
qbinfo.open(filename.c_str());//Open input file
while (qbinfo.fail())//In case of error
{
cout << filename << " is an incorrect input. " << endl;
cout << "Please reenter your full file name and path." << endl;//Re-do
cin >> filename;
qbinfo.open(filename.c_str());
}//end while
qbinfo.get(fullName, 21);
qbinfo >> ws;
qbinfo.get(teamABV, 4);
qbinfo >> completions >> attempts >> yards >> touchdowns >> interceptions;
cout << fullName << endl;
/*cout << teamABV << endl;
cout << completions << endl;
cout << attempts << endl;
cout << yards << endl;
cout << touchdowns << endl;
cout << interceptions << endl;*/// get first player's info
compPercent = ((completions / attempts) * 100 - 30)/20;
//cout << compPercent << endl;//get completion percent for initializer
if (compPercent > 2.375)
compPercent = 2.375;
else if (compPercent < 0)
compPercent = 0;
ypAttempt = ((yards/ attempts) - 3 ) * 1/4;
//cout << ypAttempt << endl;//get yards per attempt for initializer
if (ypAttempt > 2.375)
ypAttempt = 2.375;
else if (ypAttempt < 0)
ypAttempt = 0;
tdpAttempt = (touchdowns / attempts) * 20;
//cout << tdpAttempt << endl;//get touchdowns per attempt for initializer
if (tdpAttempt > 2.375)
tdpAttempt = 2.375;
else if (tdpAttempt < 0)
tdpAttempt = 0;
ipAttempt = 2.375 - ((interceptions / attempts ) * 25);
//cout << ipAttempt << endl;//get interceptions per atempt for initializer
if (ipAttempt > 2.375)
ipAttempt = 2.375;
else if (ipAttempt < 0)
ipAttempt = 0;
qbRating = ((compPercent + ypAttempt + tdpAttempt + ipAttempt) / 6 ) * 100;
cout << qbRating << endl; // output qb rating and name for initializer
while (getline(qbinfo, line))
{
qbinfo.get(fullName, 21);
qbinfo >> ws;
qbinfo.get(teamABV, 4);
qbinfo >> completions >> attempts >> yards >> touchdowns >> interceptions;
qbinfo >> ws;
cout << fullName << endl;
/* cout << teamABV << endl;
cout << completions << endl;
cout << attempts << endl;
cout << yards << endl;
cout << touchdowns << endl;
cout << interceptions << endl;*///loop info through rest of file
compPercent = ((completions / attempts) * 100 - 30)/20;
//cout << compPercent << endl;//get completion percent for loop
if (compPercent > 2.375)
compPercent = 2.375;
else if (compPercent < 0)
compPercent = 0;
ypAttempt = ((yards/ attempts) - 3 ) * 1/4;
//cout << ypAttempt << endl;//get yards per attempt for loop
if (ypAttempt > 2.375)
ypAttempt = 2.375;
else if (ypAttempt < 0)
ypAttempt = 0;
tdpAttempt = (touchdowns / attempts) * 20;
//cout << tdpAttempt << endl;//get touchdowns per attempt for loop
if (tdpAttempt > 2.375)
tdpAttempt = 2.375;
else if (tdpAttempt < 0)
tdpAttempt = 0;
ipAttempt = 2.375 - ((interceptions / attempts ) * 25);
//cout << ipAttempt << endl;//get interceptions per attempt for loop
if (ipAttempt > 2.375)
ipAttempt = 2.375;
else if (ipAttempt < 0)
ipAttempt = 0;
qbRating = ((compPercent + ypAttempt + tdpAttempt + ipAttempt) / 6 ) * 100;
cout << qbRating << endl;//output qb rating and name for loop
}//end while()
qbinfo.close();
system("pause");
}
|