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
|
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
int loadArrays(int[],int[],int[],int[],int[]);
void calcBatAvg(int[], int[], int[], int[]);
void printStats(int[], int[], int[], int[], int[], int[], int);
int main()
{
const int SIZE = 20;
int playerNum[SIZE], atBats[SIZE], hits[SIZE],
runs[SIZE], rbis[SIZE], batAvg[SIZE],numberOfPlayers;
numberOfPlayers = loadArrays(playerNum, atBats, hits, runs, rbis);
//cout << numberOfPlayers << endl;
//calcBatAvg(batAvg, hits, atBats, numberOfPlayers);
printStats(playerNum, atBats, hits, runs, rbis, batAvg, numberOfPlayers);
system("pause");
return (0);
}
int loadArrays(int playerNum[],int atBats[],int hits[],int runs[],int rbis[])
{
int i = 0, numberOfPlayers = 0;
ifstream inFile;
inFile.open("BaseballStats.txt");
if (inFile.fail())
cout << "There was an error opening the file.\n";
while (inFile >> playerNum[i])
{
inFile >> atBats[i];
inFile >> hits[i];
inFile >> runs[i];
inFile >> rbis[i];
//cout << playerNum[i] << " " << atBats[i] << " " << hits[i]
//<< " " << runs[i] << " " << rbis[i] << endl;
i++;
}
inFile.close();
return i;
}
void calcBatAvg(int batAvg[], int hits[], int atBats[], int numberOfPlayers)
{
for (int i = 0; i < numberOfPlayers; i++)
{
batAvg[i] = (hits[i] / atBats[i]) * 1000;
//cout << batAvg << endl; //not working!
}
}
void printStats(int player[], int bat[], int hit[], int run[], int rbi[], int bavg[], int count)
{
cout << "Player Num" << "\t" << "At Bat" << "\t" << "Hits"
<< "\t" << "Runs" << "\t" << "Bat Avg" << endl;
for (int i = 0; i <= count; i++)
{
cout << player[i] << "\t" << bat[i] << "\t"
<< hit[i] << "\t" << run[i] << "\t" << rbi[i]
<< "\t" << bavg[i] << endl;
}
}
|