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
|
#include <iostream>
#include <iomanip>
#include <fstream>
const int MAX = 35;
int goals[MAX];
int assists[MAX];
std::string playerNames[MAX];
int buildAr(std::string playerNames[MAX], int goals[MAX], int assists[MAX]);
void printAr(std::string playerNames[MAX], int goals[MAX], int assists[MAX], int numPlayers);
void sortAr(std::string playerNames[MAX], int goals[MAX], int assists[MAX], int numPlayers );
using namespace std;
int main()
{
int numPlayers;
numPlayers = buildAr(playerNames[MAX], goals[MAX], numPlayers);
printAr(playerNames[MAX], goals[MAX], assists[MAX], numPlayers);
return 0;
}
///////////////////////////////////////////////////////////
void printAr (std::string playerNames[MAX], int goals[MAX], int assists[MAX], int numPlayers)
{
int i = 0;
int pnts;
pnts= goals[i] + assists[i];
while((i-1)<=numPlayers)
{
cout<<playerNames[i]<<setw(6)<<goals[i]<<setw(6)<<assists[i]<<setw(6)<<pnts;
i++;
}
}
/////////////////////////////////////////////////////////////////
int buildAr(std::string playerNames[MAX], int goals[MAX], int assists[MAX])
{
int gls;
int ats;
std::string playersName;
std::ifstream statFile;
statFile.open("C:\\Users\\DREWTOP\\Desktop\\School Work\\CSCI\\hockey.txt");
int sub1=0;
if ( statFile.fail() )
{
cout << "open for hockey.txt failed";
exit(-1);
}
statFile>>playersName;
while(statFile)
{
statFile>>gls;
statFile>>ats;
playerNames[sub1]=playersName;
goals[sub1]=gls;
assists[sub1]=ats;
cout<<playerNames[sub1]<<endl;
statFile>>playersName;
sub1+=1;
}
cout<<sub1;
statFile.close();
return sub1 + 1;
}
|