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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
|
[code]
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstring>
#include <cstdlib>
//#include "inputFile.h"
using namespace std;
/********************************************************************
*** FUNCTION <name of function> ***
*********************************************************************
*** DESCRIPTION : <detailed english description of the function> ***
*** INPUT ARGS : <list of all input argument names> ***
*** OUTPUT ARGS : <list of all output argument names> ***
*** IN/OUT ARGS : <list of all input/output argument names> ***
*** RETURN : <return type and return value name> ***
********************************************************************/
const int LINE_SIZE = 80;
const int LEAGUE_SIZE = 12;
typedef char Line[LINE_SIZE]; //typedef Line
struct Team
{
char Line;
int wins;
int losses;
int ties;
int totalPoints;
int PPG;
}; //Team Structure
struct LeagueTotals
{
int totalWins;
int totalLosses;
int totalTies;
int totalPoints;
int totalPPG;
}; //LeagueTotals Structure
//************************************************************//
// Function Prototypes //
//************************************************************//
void introduction();
void stringBuild(fstream &inputFile, Line& oneLine, Line& oneString, int &pos);
char readFile(Team teams[], int LEAGUE_SIZE, Line& filename ) ;
void teamStatistics(Team teams[LEAGUE_SIZE], LeagueTotals LeagueStats, Line& filename);
void teamSort(Team teams[LEAGUE_SIZE], LeagueTotals LeagueStats, Line& filename);
int main( const int argc, const char* argv[], Line &filename) // general solution algorithm
{
Team teams[LEAGUE_SIZE];
LeagueTotals leagueStats;
Line oneLine;
Line oneString;
//Line filename;
ifstream inFile;
char ch;
int pos = 0;
introduction();
cout << "Reading data from the file.\n\n";
inFile.open("ushl.txt");
cout << "Reading File" << endl << endl;
readFile(teams[], &LEAGUE_SIZE, &filename ) ;
stringBuild(inFile, &oneLine, &oneString, &pos);
teamStatistics(teams[LEAGUE_SIZE], LeagueStats, &filename);
teamSort(teams[LEAGUE_SIZE], LeagueStats, &filename);
return 0;
}
/********************************************************************
*** FUNCTION <Introduction> ***
*********************************************************************
*** DESCRIPTION : <This function will display the process of program> ***
*** INPUT ARGS : <No arguments> ***
*** OUTPUT ARGS : <No arguments> ***
*** IN/OUT ARGS : <No arguments> ***
*** RETURN : <void return type returning no values> ***
********************************************************************/
void introduction()
{
cout << "This program will use a data file to process league statistics"
<< " for the Western Collegiate Hockey Association using an array of"
<< " structure variables and display the results sorted into"
<< " alphabetical order.";
}
/********************************************************************
*** FUNCTION <readFile> ***
*********************************************************************
*** DESCRIPTION : <This function will open the file inputed from
: the user and copy the string inside StringBuild
: which is being called inside this function.> ***
*** INPUT ARGS : <Line& oneLine, Team teams[LEAGUE_SIZE]> ***
*** OUTPUT ARGS : <> ***
*** IN/OUT ARGS : <stringBuild function, teams> ***
*** RETURN : <return type and return value name> ***
********************************************************************/
char readFile(Team teams[], int& LEAGUE_SIZE, Line& filename )
{
ifstream inFile;
char ch;
int pos = 0;
cout << "Please enter the file name";
cin >> fileName;
inFile.open(filename);
if(!inFile)
{
cerr << "Error on retreving file" << endl
<< "Please press any key to continue";
cin.get(ch);
}
else
{
//strncpy(filename, argv[1], strlen(argv[1]) + 1 ); //verify string length?
while (!inFile.getline(oneLine, LINE_SIZE, '\n').eof() )
{
stringBuild(oneLine, oneString, pos);
strcpy(teams[i].name, oneString);
stringBuild(oneLine, oneString, pos);
strcpy(teams[i].wins, oneString);
stringBuild(oneLine, oneString, pos);
strcpy(teams[i].losses, oneString);
stringBuild(oneLine, oneString, pos);
strcpy(teams[i].ties, oneString);
i++;
}//end of while loop
LEAGUE_SIZE = i;
inFile.close();
}//end of else statement
return;
}//end of readFile
/********************************************************************
*** FUNCTION <stringBuild> ***
*********************************************************************
*** DESCRIPTION : <This function will check each position for a character>
: <and return each string to readFile function> ***
*** INPUT ARGS : <inputFile, oneLine, oneString, pos> ***
*** OUTPUT ARGS : <pos, oneString,> ***
*** IN/OUT ARGS : <pos, oneString> ***
*** RETURN : <void return type returning pos and oneString value> ***
********************************************************************/
void stringBuild(fstream &inputFile, Line &oneLine, Line &oneString, int &pos)
{
int loc = 0;
while(oneLine[pos] == " ")
oneLine[++pos];
while(oneLine[pos] != " " && oneLine[pos] != '\0')
{
oneString[loc] = oneLine[pos];
pos++;
loc++;
} //while
oneString[loc] == '/0';
pos++;
return(oneString);
}
/********************************************************************
*** FUNCTION <name of function> ***
*********************************************************************
*** DESCRIPTION : <detailed english description of the function> ***
*** INPUT ARGS : <list of all input argument names> ***
*** OUTPUT ARGS : <list of all output argument names> ***
*** IN/OUT ARGS : <list of all input/output argument names> ***
*** RETURN : <return type and return value name> ***
********************************************************************/
void teamStatistics(Teams teams[LEAGUE_SIZE], LeagueTotals LeagueStats, Line &filename)
{
int totalWins = 0;
int totalLosses = 0;
int totalTies = 0;
int totalPoints = 0;
int totalPPG = 0;
//for(int team =0; team < LEAGUE_SIZE; ++team)
// {
wins * 2 = points;
ties += points;
pointsPerGame = points / numGames;
// }
}
/********************************************************************
*** FUNCTION <name of function> ***
*********************************************************************
*** DESCRIPTION : <detailed english description of the function> ***
*** INPUT ARGS : <list of all input argument names> ***
*** OUTPUT ARGS : <list of all output argument names> ***
*** IN/OUT ARGS : <list of all input/output argument names> ***
*** RETURN : <return type and return value name> ***
********************************************************************/
void teamSort(Team teams[LEAGUE_SIZE], LeagueTotals LeagueStats)
{
bool swap;
int temp;
do
{
swap = false;
for(int count = 0; count < (size -1); count++)
{
if(array[count] > array[count + 1]
{
temp = array[count];
array[count] = array[count + 1];
array[count + 1] = temp;
swap = true;
}//ends if statement
}//ends for loop
}while(swap);
}//ends TeamSort
[code]
|