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
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct playerInfo
{
string recordType,
playerId,
firstName,
lastName,
division,
team;
double plateAppearances,
atBats,
singles,
doubles,
triples,
homeRun,
sacFlys,
walks,
hitByPitch,
battingAverage,
onBasePercentage,
sluggingPercentage;
};
int main()
{
playerInfo playerStats[500];
playerInfo newPlayerStats[500];
int counter = 0;
int otherCounter = 0;
ifstream masterData("Master_Data.csv");
ifstream newStats("2014_League_Stats.csv");
if (masterData.is_open())
{
while (!masterData.eof())
{
getline(masterData, playerStats[counter].playerId, ',');
getline(masterData, playerStats[counter].firstName, ',');
getline(masterData, playerStats[counter].lastName, ',');
getline(masterData, playerStats[counter].division, ',');
getline(masterData, playerStats[counter].team, ',');
masterData >> playerStats[counter].plateAppearances;
masterData.ignore(',');
masterData >> playerStats[counter].atBats;
masterData.ignore(',');
masterData >> playerStats[counter].singles;
masterData.ignore(',');
masterData >> playerStats[counter].doubles;
masterData.ignore(',');
masterData >> playerStats[counter].triples;
masterData.ignore(',');
masterData >> playerStats[counter].homeRun;
masterData.ignore(',');
masterData >> playerStats[counter].sacFlys;
masterData.ignore(',');
masterData >> playerStats[counter].walks;
masterData.ignore(',');
masterData >> playerStats[counter].hitByPitch;
masterData.ignore(',');
masterData >> playerStats[counter].battingAverage;
masterData.ignore(',');
masterData >> playerStats[counter].onBasePercentage;
masterData.ignore(',');
masterData >> playerStats[counter].sluggingPercentage;
masterData.ignore(',');
}
}
else
{
cout << "Error Reading File" << endl;
}
if (newStats.is_open())
{
while (!newStats.eof())
{
getline(newStats, newPlayerStats[otherCounter].recordType, ',');
getline(newStats, newPlayerStats[otherCounter].playerId, ',');
getline(newStats, newPlayerStats[otherCounter].firstName, ',');
getline(newStats, newPlayerStats[otherCounter].lastName, ',');
getline(newStats, newPlayerStats[otherCounter].division, ',');
getline(newStats, newPlayerStats[otherCounter].team, ',');
newStats >> newPlayerStats[otherCounter].plateAppearances;
newStats.ignore(',');
newStats >> newPlayerStats[otherCounter].atBats;
newStats.ignore(',');
newStats >> newPlayerStats[otherCounter].singles;
newStats.ignore(',');
newStats >> newPlayerStats[otherCounter].doubles;
newStats.ignore(',');
newStats >> newPlayerStats[otherCounter].triples;
newStats.ignore(',');
newStats >> newPlayerStats[otherCounter].homeRun;
newStats.ignore(',');
newStats >> newPlayerStats[otherCounter].sacFlys;
newStats.ignore(',');
newStats >> newPlayerStats[otherCounter].walks;
newStats.ignore(',');
newStats >> newPlayerStats[otherCounter].hitByPitch;
newStats.ignore(',');
newStats >> newPlayerStats[otherCounter].battingAverage;
newStats.ignore(',');
newStats >> newPlayerStats[otherCounter].onBasePercentage;
newStats.ignore(',');
newStats >> newPlayerStats[otherCounter].sluggingPercentage;
newStats.ignore(',');
}
}
else
{
cout << "Error Reading File" << endl;
}
masterData.close();
newStats.close();
system("pause");
return 0;
}
|