Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Steven Green
- //MIS 120 Final Project
- //In this project,
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- #include <string>
- #include <ctype.h>
- #include <cmath>
- using namespace std;
- struct masterFileStruct {
- int round, minsPlayed, point2Attempt, point2Made, point3Attempt, point3Made;
- int fThrowsAttempt, fThrowsMade, numFouls, numTurnovers, numPoints;
- double point2Percent, point3Percent, freeThrowsPrecent;
- char actionCode, recordType;
- string playerID, firstName, lastName, leagueName, teamName, tempstring;
- };
- struct updateFileStruct {
- int round, minsPlayed, point2Attempt, point2Made, point3Attempt, point3Made;
- int fThrowsAttempt, fThrowsMade, numFouls, numTurnovers, numPoints;
- double point2Percent, point3Percent, freeThrowsPrecent;
- char actionCode, recordType;
- string playerID, firstName, lastName, leagueName, teamName, tempstring;
- };
- void spacer();
- void perror();
- void fileinput(masterFileStruct masterPlayers[1999], updateFileStruct updatePlayers[1999], int sub);
- void outputTest(masterFileStruct masterPlayers[1999], updateFileStruct updatePlayers[1999], int sub);
- void teamSort(masterFileStruct masterPlayers[1999], updateFileStruct updatePlayers[1999], int sub);
- void playerSort(masterFileStruct masterPlayers[1999], updateFileStruct updatePlayers[1999], int sub);
- //int updateRecord();
- //void reportFileOutput();
- //void calculateStates();
- //void top20();
- //void top5();
- int main()
- {
- int sub = 0;
- masterFileStruct masterPlayers [1999];
- updateFileStruct updatePlayers [1999];
- spacer();
- //inputfile
- fileinput(masterPlayers, updatePlayers, sub);
- //output to round stats
- spacer();
- system("pause");
- return 0;
- }
- void fileinput(masterFileStruct masterPlayers[1999], updateFileStruct updatePlayers[1999], int sub)
- {
- ifstream inFile;
- string hfileName, hfileDate, tfileName, tfileDate;
- char actionCode, recordType, drecordType, trecordType;
- int hRound, tRound, pointsSum;
- inFile.open("roundInput.txt", ios::in);
- if (inFile.is_open())
- {
- //cout << "File Opened!" << endl;
- while (!inFile.eof())
- {
- inFile >> recordType;
- if (recordType == 'H')
- {
- //header record
- inFile.ignore();
- getline(inFile, hfileName, ',');
- getline(inFile, hfileDate, ',');
- inFile >> hRound;
- inFile.ignore();
- }
- else if (recordType == 'D')
- {
- //detail record
- inFile.ignore();
- inFile >> actionCode;
- inFile.ignore();
- inFile >> updatePlayers[sub].round;
- inFile.ignore();
- getline(inFile, updatePlayers[sub].playerID, ',');
- getline(inFile, updatePlayers[sub].firstName, ',');
- getline(inFile, updatePlayers[sub].lastName, ',');
- getline(inFile, updatePlayers[sub].leagueName, ',');
- getline(inFile, updatePlayers[sub].teamName, ',');
- inFile >> updatePlayers[sub].minsPlayed;
- inFile.ignore();
- inFile >> updatePlayers[sub].point2Attempt;
- inFile.ignore();
- inFile >> updatePlayers[sub].point2Made;
- inFile.ignore();
- inFile >> updatePlayers[sub].point3Attempt;
- inFile.ignore();
- inFile >> updatePlayers[sub].point3Made;
- inFile.ignore();
- inFile >> updatePlayers[sub].fThrowsAttempt;
- inFile.ignore();
- inFile >> updatePlayers[sub].fThrowsMade;
- inFile.ignore();
- inFile >> updatePlayers[sub].numFouls;
- inFile.ignore();
- inFile >> updatePlayers[sub].numTurnovers;
- inFile.ignore();
- sub++;
- }
- else if (recordType == 'T')
- {
- //trailer record
- inFile.ignore();
- getline(inFile, tfileName, ',');
- getline(inFile, tfileDate, ',');
- inFile >> tRound;
- inFile.ignore();
- inFile >> pointsSum;
- inFile.ignore();
- }
- else
- {
- perror();
- }
- outputTest(masterPlayers, updatePlayers, sub);
- system("pause");
- spacer();
- }
- }
- }
- void outputTest(masterFileStruct masterPlayers[1999], updateFileStruct updatePlayers[1999], int sub)
- {
- cout << "round:" << updatePlayers[sub].round << endl;
- cout << "playerID:" << updatePlayers[sub].playerID << endl;
- cout << "firstName:" << updatePlayers[sub].firstName << endl;
- cout << "lastName:" << updatePlayers[sub].lastName << endl;
- cout << "leagueName:" << updatePlayers[sub].leagueName << endl;
- cout << "teamName:" << updatePlayers[sub].teamName << endl;
- cout << "minsPlayed:" << updatePlayers[sub].minsPlayed << endl;
- cout << "point2Attempt:" << updatePlayers[sub].point2Attempt << endl;
- cout << "point2Made:" << updatePlayers[sub].point2Made << endl;
- cout << "point3Attempt:" << updatePlayers[sub].point3Attempt << endl;
- cout << "point3Made:" << updatePlayers[sub].point3Made << endl;
- cout << "fThrowsAttempt:" << updatePlayers[sub].fThrowsAttempt << endl;
- cout << "fThrowsMade:" << updatePlayers[sub].fThrowsMade << endl;
- cout << "numFouls:" << updatePlayers[sub].numFouls << endl;
- cout << "numTurnovers:" << updatePlayers[sub].numTurnovers << endl;
- }
- void playerSort(masterFileStruct masterPlayers[1999], updateFileStruct updatePlayers[1999], int sub)
- {
- string tempString;
- int maxi = 0;
- int lastSwap = 0;
- char swap = 'Y';
- while (swap == 'Y')
- {
- swap = 'N';
- while (sub < maxi)
- {
- if (updatePlayers[sub].playerID < updatePlayers[sub + 1].playerID)
- {
- tempString = updatePlayers[sub].playerID;
- updatePlayers[sub].playerID = updatePlayers[sub + 1].playerID;
- updatePlayers[sub + 1].playerID = tempString;
- swap = 'Y';
- lastSwap = sub;
- }//end if
- sub ++;
- }//end while
- maxi = lastSwap;
- }//end while
- }//end function
- void teamSort(masterFileStruct masterPlayers[1999], updateFileStruct updatePlayers[1999], int sub)
- {
- string tempString;
- int maxi = 0;
- int lastSwap = 0;
- char swap = 'Y';
- while (swap == 'Y')
- {
- swap = 'N';
- while (sub < maxi)
- {
- if (updatePlayers[sub].teamName < updatePlayers[sub + 1].teamName)
- {
- tempString = updatePlayers[sub].teamName;
- updatePlayers[sub].teamName = updatePlayers[sub + 1].teamName;
- updatePlayers[sub + 1].teamName = tempString;
- swap = 'Y';
- lastSwap = sub;
- }//end if
- sub ++;
- }//end while
- maxi = lastSwap;
- }//end while
- }//end function
- /*int updateRecord()// update each record
- {
- return ;
- }
- //void reportFileOutput();
- /*
- example
- ---Round#---
- Team A summary
- Team B summary
- Team C summary
- ---Round#+1---
- Team A summary
- Team B summary
- Team C summary
- */
- void spacer()
- {
- for (int z = 1; z <35; z++)
- {
- cout << "-";
- }
- cout << "\n";
- }
- void perror()
- {
- cout << "ERROR IN FILE!\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement