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 162 163 164 165 166 167 168 169
|
// extraola.cc By Mike Myers CSCI 1170-001, Due 07/05/2012
//
// PROGRAM ID: extraola
// AUTHOR: Mike Myers
// REMARKS: This program will calculate how to find the MVP in the NBA
#include<iostream>
#include<string>
#include<cassert>
#include<iomanip>
#include<fstream>
using namespace std;
const int MAX_PLAYERS =500;
struct Playersinfo
{
string name; // players name
string team; //players team
int GP; // Number of games played
float PTS; // Average points per game
float MPG; // Minutes played per game
float FGM; //number of FGmade per game
float FGA; //number of FG attempted
float FGP; //FG %
float threePM; // number of 3 points made
float threePP; // 3 point %
float threePA; // 3 points attempted
float FTM; // free throws made
float FTA; // free throwsattempted
float FTP; // free throw %
float score; // players score
};
void Readinfo (Playersinfo players[], int& count);
float CalcScore(Playersinfo player );
void FindMVP (Playersinfo players[], int count);
int Search(string array[], string FindNum, int& count1);
void winningTeam(Playersinfo players[], int count);
int main()
{
int count=0;
Playersinfo players[MAX_PLAYERS];
Readinfo( players, count);
FindMVP(players, count);
winningTeam(players, count);
return 0;
}
//Calculates MVP scores for the play
float CalcScore(Playersinfo player)
{
float score;
float threePP = player.threePP;
float FTP = player.FTP;
float FGP = player.FGP;
float PTS = player.PTS;
float GP = player.GP;
score = (threePP + FTP + FGP)/3 * 100 * PTS * GP;
return score;
}
// calculates MVP score for player
void Readinfo (Playersinfo player[], int& count)
{
ifstream myData;
myData.open("nba.dat");
assert(myData);
Playersinfo Playerinput;
char space;
getline(myData.Playerinput.name);
while(myData)
{
myData>>Playerinput.team >>
Playerinput.GP >>
Playerinput.PTS >>
Playerinput.MPG >>
Playerinput.FGM >>
space >>
Playerinput.FGA >>
Playerinput.FGP >>
Playerinput.threePM >>
space >>
Playerinput.threePM >>
Playerinput.threePP >>
Playerinput.FTM >>
space >>
Playerinput.FTA >>
Playerinput.FTP;
myData.ingore(100,'\n');
Playerinput.score= CalcScore(Playerinput);
player[count] = Playerinput;
count++;
getline(myData,Playerinput.name);
}
myData.close();
return;
}
//finds MVP based on the highest score
void FindMVP (Playersinfo players[], int count)
{
float largest =0;
int index = 0;
for(int i=0; i<count; i++)
{
if(players[i].score>largest)
{
largest = players[i].score;
index=i;
}
}
cout<< "The MVP for the year is " << players[index].name << "with a score of " << players[index].score<< endl;
}
int Search(string array[], string FindNum, int& count1)
{
for(int i=0; i<count1; i++)
{
if(array[i] == FindNum)
return i;
}
return -1;
}
// Tells the Winning Team
void winningTeam(Playersinfo players[], int count)
{
string arrayTeam[MAX_PLAYERS];
int arrayCount[MAX_PLAYERS];
float arrayScores[MAX_PLAYERS];
Playersinfo Playerinput;
int index;
int teams=0;
float average;
float largest = 0;
for(int i=0; i<count; i++)
{
Playerinput = players[i];
index = Search (arrayTeam, Playerinput.team, teams);
if(index== -1)
{
arrayTeam[teams] = Playerinput.team;
arrayScores[teams] =Playerinput.score;
arrayCount[teams] = 1;
teams++;
}
else
{
arrayScores[index] = arrayScores[index] +Playerinput.score;
arrayCount[index] = arrayCount[index] +1;
}
}
for(int j=0; j<teams; j++)
{
average = arrayScores[j]/arrayCount[j];
if (average>largest)
{
largest = average;
index=j;
}
}
cout << "The winning team is " << arrayTeam[index] << "with an average score of " << largest << endl;
return;
}
|