Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.47 KB | None | 0 0
  1. //Steven Green
  2. //MIS 120 Final Project
  3. //In this project,
  4.  
  5. #include <iostream>
  6. #include <iomanip>
  7. #include <fstream>
  8. #include <string>
  9. #include <ctype.h>
  10. #include <cmath>
  11.  
  12. using namespace std;
  13.  
  14. struct masterFileStruct {
  15.     int round, minsPlayed, point2Attempt, point2Made, point3Attempt, point3Made;
  16.     int  fThrowsAttempt, fThrowsMade, numFouls, numTurnovers, numPoints;
  17.     double point2Percent, point3Percent, freeThrowsPrecent;
  18.     char actionCode, recordType;
  19.     string playerID, firstName, lastName, leagueName, teamName, tempstring;
  20. };
  21.  
  22. struct updateFileStruct {
  23.     int round, minsPlayed, point2Attempt, point2Made, point3Attempt, point3Made;
  24.     int  fThrowsAttempt, fThrowsMade, numFouls, numTurnovers, numPoints;
  25.     double point2Percent, point3Percent, freeThrowsPrecent;
  26.     char actionCode, recordType;
  27.     string playerID, firstName, lastName, leagueName, teamName, tempstring;
  28. };
  29.  
  30. void spacer();
  31. void perror();
  32. void fileinput(masterFileStruct masterPlayers[1999], updateFileStruct updatePlayers[1999], int sub);
  33. void outputTest(masterFileStruct masterPlayers[1999], updateFileStruct updatePlayers[1999], int sub);
  34. void teamSort(masterFileStruct masterPlayers[1999], updateFileStruct updatePlayers[1999], int sub);
  35. void playerSort(masterFileStruct masterPlayers[1999], updateFileStruct updatePlayers[1999], int sub);
  36. //int updateRecord();
  37. //void reportFileOutput();
  38. //void calculateStates();
  39. //void top20();
  40. //void top5();
  41.  
  42.  
  43. int main()
  44. {
  45.     int sub = 0;
  46.     masterFileStruct masterPlayers [1999];
  47.     updateFileStruct updatePlayers [1999];
  48.     spacer();
  49.     //inputfile
  50.     fileinput(masterPlayers, updatePlayers, sub);
  51.     //output to round stats
  52.     spacer();
  53.  
  54.     system("pause");
  55.     return 0;
  56. }
  57.  
  58.  
  59. void fileinput(masterFileStruct masterPlayers[1999], updateFileStruct updatePlayers[1999], int sub)
  60. {
  61.     ifstream inFile;
  62.  
  63.     string hfileName, hfileDate, tfileName, tfileDate;
  64.     char  actionCode, recordType, drecordType, trecordType;
  65.     int hRound, tRound, pointsSum;
  66.     inFile.open("roundInput.txt", ios::in);
  67.     if (inFile.is_open())
  68.     {
  69.         //cout << "File Opened!" << endl;
  70.         while (!inFile.eof())
  71.         {
  72.             inFile >> recordType;
  73.  
  74.             if (recordType == 'H')
  75.             {
  76.                 //header record
  77.                 inFile.ignore();
  78.                 getline(inFile, hfileName, ',');
  79.                 getline(inFile, hfileDate, ',');
  80.                 inFile >> hRound;
  81.                 inFile.ignore();
  82.             }
  83.    
  84.             else if (recordType == 'D')
  85.             {
  86.                 //detail record
  87.                 inFile.ignore();
  88.                 inFile >> actionCode;
  89.                 inFile.ignore();
  90.                 inFile >> updatePlayers[sub].round;
  91.                 inFile.ignore();
  92.                 getline(inFile, updatePlayers[sub].playerID, ',');
  93.                 getline(inFile, updatePlayers[sub].firstName, ',');
  94.                 getline(inFile, updatePlayers[sub].lastName, ',');
  95.                 getline(inFile, updatePlayers[sub].leagueName, ',');
  96.                 getline(inFile, updatePlayers[sub].teamName, ',');
  97.                 inFile >> updatePlayers[sub].minsPlayed;
  98.                 inFile.ignore();
  99.                 inFile >> updatePlayers[sub].point2Attempt;
  100.                 inFile.ignore();
  101.                 inFile >> updatePlayers[sub].point2Made;
  102.                 inFile.ignore();
  103.                 inFile >> updatePlayers[sub].point3Attempt;
  104.                 inFile.ignore();
  105.                 inFile >> updatePlayers[sub].point3Made;
  106.                 inFile.ignore();
  107.                 inFile >> updatePlayers[sub].fThrowsAttempt;
  108.                 inFile.ignore();
  109.                 inFile >> updatePlayers[sub].fThrowsMade;
  110.                 inFile.ignore();
  111.                 inFile >> updatePlayers[sub].numFouls;
  112.                 inFile.ignore();
  113.                 inFile >> updatePlayers[sub].numTurnovers;
  114.                 inFile.ignore();
  115.                 sub++;
  116.             }
  117.             else if (recordType == 'T')
  118.             {
  119.                 //trailer record
  120.                 inFile.ignore();
  121.                 getline(inFile, tfileName, ',');
  122.                 getline(inFile, tfileDate, ',');
  123.                 inFile >> tRound;
  124.                 inFile.ignore();
  125.                 inFile >> pointsSum;
  126.                 inFile.ignore();
  127.             }
  128.             else
  129.             {
  130.                 perror();
  131.             }
  132.            
  133.             outputTest(masterPlayers, updatePlayers, sub);
  134.             system("pause");
  135.             spacer();
  136.            
  137.  
  138.  
  139.         }
  140.     }
  141. }
  142.  
  143. void outputTest(masterFileStruct masterPlayers[1999], updateFileStruct updatePlayers[1999], int sub)
  144. {
  145.     cout << "round:" << updatePlayers[sub].round << endl;
  146.     cout << "playerID:" << updatePlayers[sub].playerID << endl;
  147.     cout << "firstName:" << updatePlayers[sub].firstName << endl;
  148.     cout << "lastName:" << updatePlayers[sub].lastName << endl;
  149.     cout << "leagueName:" << updatePlayers[sub].leagueName << endl;
  150.     cout << "teamName:" << updatePlayers[sub].teamName << endl;
  151.     cout << "minsPlayed:" << updatePlayers[sub].minsPlayed << endl;
  152.     cout << "point2Attempt:" << updatePlayers[sub].point2Attempt << endl;
  153.     cout << "point2Made:" << updatePlayers[sub].point2Made << endl;
  154.     cout << "point3Attempt:" << updatePlayers[sub].point3Attempt << endl;
  155.     cout << "point3Made:" << updatePlayers[sub].point3Made << endl;
  156.     cout << "fThrowsAttempt:" << updatePlayers[sub].fThrowsAttempt << endl;
  157.     cout << "fThrowsMade:" << updatePlayers[sub].fThrowsMade << endl;
  158.     cout << "numFouls:" << updatePlayers[sub].numFouls << endl;
  159.     cout << "numTurnovers:" << updatePlayers[sub].numTurnovers << endl;
  160.  
  161.  
  162. }
  163.  
  164. void playerSort(masterFileStruct masterPlayers[1999], updateFileStruct updatePlayers[1999], int sub)
  165. {
  166.     string tempString;
  167.     int maxi = 0;
  168.     int lastSwap = 0;
  169.     char swap = 'Y';
  170.  
  171.     while (swap == 'Y')
  172.     {
  173.         swap = 'N';
  174.  
  175.  
  176.         while (sub < maxi)
  177.         {
  178.             if (updatePlayers[sub].playerID < updatePlayers[sub + 1].playerID)
  179.             {
  180.                 tempString = updatePlayers[sub].playerID;
  181.                 updatePlayers[sub].playerID = updatePlayers[sub + 1].playerID;
  182.                 updatePlayers[sub + 1].playerID = tempString;
  183.                 swap = 'Y';
  184.                 lastSwap = sub;
  185.             }//end if
  186.             sub ++;
  187.         }//end while
  188.         maxi = lastSwap;
  189.     }//end while
  190. }//end function
  191.  
  192. void teamSort(masterFileStruct masterPlayers[1999], updateFileStruct updatePlayers[1999], int sub)
  193. {
  194.    
  195.     string tempString;
  196.     int maxi = 0;
  197.     int lastSwap = 0;
  198.     char swap = 'Y';
  199.  
  200.     while (swap == 'Y')
  201.     {
  202.         swap = 'N';
  203.  
  204.  
  205.         while (sub < maxi)
  206.         {
  207.             if (updatePlayers[sub].teamName < updatePlayers[sub + 1].teamName)
  208.             {
  209.                 tempString = updatePlayers[sub].teamName;
  210.                 updatePlayers[sub].teamName = updatePlayers[sub + 1].teamName;
  211.                 updatePlayers[sub + 1].teamName = tempString;
  212.                 swap = 'Y';
  213.                 lastSwap = sub;
  214.             }//end if
  215.             sub ++;
  216.         }//end while
  217.         maxi = lastSwap;
  218.     }//end while
  219. }//end function
  220.  
  221. /*int updateRecord()// update each record
  222. {
  223.     return ;
  224. }
  225. //void reportFileOutput();
  226. /*
  227. example
  228. ---Round#---
  229. Team A summary
  230. Team B summary
  231. Team C summary
  232. ---Round#+1---
  233. Team A summary
  234. Team B summary
  235. Team C summary
  236. */
  237. void spacer()
  238. {
  239.     for (int z = 1; z <35; z++)
  240.     {
  241.         cout << "-";
  242.     }
  243.     cout << "\n";
  244. }
  245.  
  246. void perror()
  247. {
  248.     cout << "ERROR IN FILE!\n";
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement