Advertisement
andrefecto

open superbowl.dat

Dec 9th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. #include <fstream>
  5. #include <cstdlib>
  6. #include <unistd.h>
  7.  
  8. using namespace std;
  9.  
  10. /*
  11. // Declarations
  12. // Initalizations
  13. // Input
  14. // Process
  15. // Output
  16. // Prolouge
  17. */
  18. void openFile(ifstream& in)
  19. {
  20.     // Declarations
  21.     string file = "superbowl.dat";
  22.     // Initalizations
  23.         // My variables are initalized with my declarations
  24.     // Input
  25.     // Process
  26.     in.open( file.c_str() );
  27.     // Output
  28.     if(in.fail() )
  29.     {
  30.         cout << "The superbow.dat file doesn't exist. \nThe program will now quit so you can put the file in correct folder.";
  31.     }
  32.     // Prolouge
  33. }
  34. void lines(ifstream& in, string winner[], string loser[], double score[])
  35. {
  36. // Declarations
  37. // Initalizations
  38. // Input
  39. // Process
  40.     for(int i = 0; i < 47; i++)
  41.     {
  42.         in >> winner[i];
  43.         in >> loser[i];
  44.         in >> score[i];
  45.     }
  46. // Output
  47. // Prolouge
  48. }
  49. void averageScores(double score[], double& average)
  50. {
  51. // Declarations
  52.     double temp = 0.0;
  53.     double temp2 = 0.0;
  54.     const double four7 = 47;
  55. // Initalizations
  56.         // All my variables are initalized above with the delarations
  57. // Input
  58. // Process
  59.     for(int i=0; i < 47; i++)
  60.     {
  61.         temp = temp2 + score[i];
  62.         temp2 = temp;
  63.     }
  64.     average = temp2 / four7;
  65. // Output
  66. // Prolouge
  67. }
  68. void highest(double& highScore, double score[], int& arrayPlace)
  69. {
  70. // Declarations
  71. // Initalizations
  72. // Input
  73. // Process
  74.     for(int i = 0; i < 47; i++)
  75.     {
  76.         if(highScore < score[i])
  77.         {
  78.             highScore=score[i];
  79.             arrayPlace = i;
  80.         }
  81.     }
  82. // Output
  83. // Prolouge
  84. }
  85. void least(double& leastScore, double score[], int& arrayPlace2, double& highScore)
  86. {
  87. // Declarations
  88. // Initalizations
  89.     leastScore = highScore;
  90. // Input
  91. // Process
  92.     for(int i = 0; i < 47; i++)
  93.     {
  94.         if(score[i] < leastScore)
  95.         {
  96.             leastScore = score[i];
  97.             arrayPlace2 = i;
  98.         }
  99.     }
  100. // Output
  101. // Prolouge
  102. }
  103. void moreThan40(double score[], int& amountAbove)
  104. {
  105. // Declarations
  106. // Initalizations
  107. // Input
  108. // Process
  109.     for(int i = 0; i < 47; i++)
  110.     {
  111.         const int above = 40;
  112.         if(score[i] > above)
  113.         {
  114.             amountAbove++;
  115.         }
  116.     }
  117. // Output
  118. // Prolouge
  119. }
  120. void output(string winner[], string loser[], double score[], double& average, double& highScore, int& arrayPlace, int& arrayPlace2, double& leastScore, int& amountAbove)
  121. {
  122. // Declarations
  123. // Initalizations
  124. // Input
  125. // Process
  126. // Output
  127.     cout << "This Program Automatically opens the superbowl.dat file. \nIt will then sort and analyze the information for you below: ";
  128.     cout << endl;
  129.     cout << left << "---------------------------------------------------" << endl;
  130.     cout << left << setw(20) << "Winner" << " | " << setw(20) << "Loser" << " | "<< setw(20) << "Score" << endl;
  131.     cout << left << "---------------------------------------------------" << endl;
  132.     for(int i = 0; i < 47; i++)
  133.     {
  134.             cout << left << setw(20) << winner[i] << " | " << setw(20) << loser[i] << " | " << setw(20) << score[i] << endl;
  135.     }
  136.     cout << left << "---------------------------------------------------" << endl;
  137.     cout <<"The Average Score is: " << average << endl;
  138.     cout << left << "---------------------------------------------------" << endl;
  139.     cout << "The Highests Scoring Game Was: " << endl;
  140.     cout << winner[arrayPlace] << " Vs. " << loser[arrayPlace] << "\nWith the " << winner[arrayPlace] << " scoring: " << highScore << " Points To Win." << endl;
  141.     cout << left << "---------------------------------------------------" << endl;
  142.     cout << "The Lowest Scoring Game Was: " << endl;
  143.     cout << winner[arrayPlace2] << " Vs. " << loser[arrayPlace2] << "\nWith the " << winner[arrayPlace2] << " scoring only: " << leastScore << " Points To Win." << endl;
  144.     cout << left << "---------------------------------------------------" << endl;
  145.     cout << "The Amount of Games That Scored More Than 40 Points is: " << amountAbove << endl;
  146.     cout << left << "---------------------------------------------------" << endl;
  147. // Prolouge
  148. }
  149. int main()
  150. {
  151. // Declarations
  152.     ifstream in;
  153.     string winner[48] = { };
  154.     string loser[48] = { };
  155.     double score[48] = { };
  156.     double highScore = 0.0;
  157.     double leastScore = 0.0;
  158.     double average = 0.0;
  159.     int amountAbove = 0;
  160.     int arrayPlace = 0;
  161.     int arrayPlace2 = 0;
  162. // Initalizations
  163.         // My variables are initalized above in the declarations
  164. // Input
  165.     openFile(in);
  166.     lines(in, winner, loser, score);
  167. // Process
  168.     averageScores(score, average);
  169.     highest(highScore, score, arrayPlace);
  170.     least(leastScore, score, arrayPlace2, highScore);
  171.     moreThan40(score, amountAbove);
  172. // Output
  173.     output(winner, loser, score, average, highScore, arrayPlace, arrayPlace2, leastScore, amountAbove);
  174. // Prolouge
  175.     in.close();
  176.     return 0;
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement