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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <cstdlib>
#include <fstream>
using namespace std;
const int games = 10; //total games played/person
const int stat = 5; //total amount of stored stats
const int players = 3; //amount of players in the file
struct playerInfo {
string name; //player name
//GAME X; completions; attempts; yards; touchdowns; interceptions
int matrix[games][stat]; //array of stats/game
};
void printPlayer(const playerInfo& p) {
//Display the name of the player and initialize the header array
cout << '\n' << p.name << '\n';
static string heading[stat] = { "Completions", "Attempts", "Yards", "Touchdowns", "Interceptions" };
//Display header
cout << " GAME";
for (int col = 0; col < stat; ++col)
cout << setw(14) << heading[col];
cout << '\n';
//Print all the stats
for (int row = 0; row < games; ++row) {
cout << setw(5) << row + 1;
for (int col = 0; col < stat; ++col)
cout << setw(14) << p.matrix[row][col];
cout << '\n';
}
cout << '\n';
}
void printPlayerStats(const playerInfo& p) {
//initialize arrays for storing stat vals, and the headers
int totalStats[stat] = {0, 0, 0, 0, 0};
static string heading[stat] = { "Completions", "Attempts", "Yards", "Touchdowns", "Interceptions" };
//Take in values to the array
for (int row = 0; row < games; row++) {
for (int col = 0; col < stat; col++) {
if (row == 0) //first row check
totalStats[col] = p.matrix[row][col];
else
totalStats[col] += p.matrix[row][col];
}
}
cout << '\n' << p.name << '\n'; //display the name
//Print the total stats
for (int x = 0; x < stat; x++)
cout << heading[x] << ": " << totalStats[x] << endl;
cout << endl;
}
double boundaries(double x) {
//defaults the passer rating back to a default state if it passes a certain number
if (x > 2.375)
x = 2.375;
if (x < 0.0)
x = 0.0;
return x; //returns the new number
}
void printPasserRatings(const playerInfo& p) {
double totalStats[stat];
for (int row = 0; row < games; row++) {
for (int col = 0; col < stat; col++) {
if (row == 0)
totalStats[col] = p.matrix[row][col];
else
totalStats[col] += p.matrix[row][col];
}
}
//Calculates every variable to the equation for a seamless calculating experience
//totalStats[0] = Completions, [1] = Attempts, [2] = Yards, [3] = Touchdowns, [4] = Interceptions
double a = ((totalStats[0] / totalStats[1]) - 0.3) * 5.0; a = boundaries(a);
double b = ((totalStats[2] / totalStats[1]) - 3.0) * .25; b = boundaries(b);
double c = (totalStats[3] / totalStats[1]) * 20.0; c = boundaries(c);
double d = 2.375 - ((totalStats[4] / totalStats[1]) * 25.0); d = boundaries(d);
cout << '\n' << p.name << '\n'; //print players name
cout << "Passer Rating: " << ((a + b + c + d) / 0.06) << '\n'; //print the players passer rating
}
int main() {
//Three players
playerInfo playerKeeper[players];
ifstream inFile("QBInfo.txt");
//checks if you can't open te file
if (inFile.fail()) {
cout << "ERROR OPENING FILE";
return 0;
}
int count = 0;
if (inFile >> count) //read number of players
inFile.ignore(100, '\n'); //discard rest of line
for (int n = 0; n < count; ++n) {
getline(inFile, playerKeeper[n].name); //read name
for (int game = 0; game < games; game++) { //read stats
for (int col = 0; col < stat; ++col)
inFile >> playerKeeper[n].matrix[game][col];
}
inFile.ignore(100, '\n'); //discard rest of line
}
inFile.close(); //closes the file since it no longer needs to be in use, or read in values
//switch ladders for the infinite menu loop deal
int choice = -1;
int player = 0;
while (choice != 4) {
do {
cout << "1. Print Player\n2. Print Player Stats\n3. Print Passer Ratings\n4. Exit\nEnter an option: ";
cin >> choice;
cout << endl;
} while (choice > 4 || choice < 1);
switch (choice) {
case 1:
cin >> player;
printPlayer(playerKeeper[player - 1]);
break;
case 2:
cin >> player;
printPlayerStats(playerKeeper[player - 1]);
break;
case 3:
for (int ply = 0; ply < players; ply++) {
printPasserRatings(playerKeeper[ply]);
}
cout << endl;
break;
case 4:
return 0; //closes the program
break;
}
}
cin.clear();
cin.ignore(255, '\n');
cin.get();
return 0;
}
|