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
|
#include<iomanip>
#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
// protoypes
int buildArray(string, int, int, int);
void printArray(string, int, int, int, int);
void sortArray(string, int, int, int, int);
int main()
{
const int size = 25;
string playerArray[size];
int goalArray[size], assistArray[size], ratingArray[size], number;
number = buildArray(playerArray[size], goalArray[size], assistArray[size], ratingArray[size]);
printArray(playerArray[size], goalArray[size], assistArray[size], ratingArray[size], number);
}
// list of functions
int buildArray(string playerNames[], int goals[], int assists[], int ratings[])
{
ifstream hockeyFile;
int i = 0, num = 0;
string name;
hockeyFile.open( "hockey.txt" );
if ( hockeyFile.fail() )
{
cout << "The hockey.txt input file did not open";
exit (-1);
}
while( hockeyFile )
{
hockeyFile >> name;
playerNames[i] = name;
hockeyFile >> num;
goals[i] = num;
hockeyFile >> num;
assists[i] = num;
hockeyFile >> num;
ratings[i] = num;
i++;
}
hockeyFile.close();
return i;
}
void printArray( string playerNames[], int goals[], int assists[], int ratings[], int number)
{
cout << "Player" << setw(15) << "Goals" << setw(15) << "Assists" << setw(15) << "Points" << setw(15) << "Plus/Minus";
for (int i = 0; i < 60; i++)
cout << "-";
for (int sub = 0; sub < number; sub++)
{
int points = goals[sub]+assists[sub];
cout << playerNames[sub] << setw(15) << goals[sub] << setw(15) << assists[sub] << setw(15) << points << setw(15) << showpos << ratings[sub];
}
}
void sortArray( string playerNames[], int goals[], int assists[], int ratings[], int number)
{
}
|