Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- #include <fstream>
- #include <cstdlib>
- #include <unistd.h>
- using namespace std;
- /*
- // Declarations
- // Initalizations
- // Input
- // Process
- // Output
- // Prolouge
- */
- void openFile(ifstream& in)
- {
- // Declarations
- string file = "superbowl.dat";
- // Initalizations
- // My variables are initalized with my declarations
- // Input
- // Process
- in.open( file.c_str() );
- // Output
- if(in.fail() )
- {
- cout << "The superbow.dat file doesn't exist. \nThe program will now quit so you can put the file in correct folder.";
- }
- // Prolouge
- }
- void lines(ifstream& in, string winner[], string loser[], double score[])
- {
- // Declarations
- // Initalizations
- // Input
- // Process
- for(int i = 0; i < 47; i++)
- {
- in >> winner[i];
- in >> loser[i];
- in >> score[i];
- }
- // Output
- // Prolouge
- }
- void averageScores(double score[], double& average)
- {
- // Declarations
- double temp = 0.0;
- double temp2 = 0.0;
- const double four7 = 47;
- // Initalizations
- // All my variables are initalized above with the delarations
- // Input
- // Process
- for(int i=0; i < 47; i++)
- {
- temp = temp2 + score[i];
- temp2 = temp;
- }
- average = temp2 / four7;
- // Output
- // Prolouge
- }
- void highest(double& highScore, double score[], int& arrayPlace)
- {
- // Declarations
- // Initalizations
- // Input
- // Process
- for(int i = 0; i < 47; i++)
- {
- if(highScore < score[i])
- {
- highScore=score[i];
- arrayPlace = i;
- }
- }
- // Output
- // Prolouge
- }
- void least(double& leastScore, double score[], int& arrayPlace2, double& highScore)
- {
- // Declarations
- // Initalizations
- leastScore = highScore;
- // Input
- // Process
- for(int i = 0; i < 47; i++)
- {
- if(score[i] < leastScore)
- {
- leastScore = score[i];
- arrayPlace2 = i;
- }
- }
- // Output
- // Prolouge
- }
- void moreThan40(double score[], int& amountAbove)
- {
- // Declarations
- // Initalizations
- // Input
- // Process
- for(int i = 0; i < 47; i++)
- {
- const int above = 40;
- if(score[i] > above)
- {
- amountAbove++;
- }
- }
- // Output
- // Prolouge
- }
- void output(string winner[], string loser[], double score[], double& average, double& highScore, int& arrayPlace, int& arrayPlace2, double& leastScore, int& amountAbove)
- {
- // Declarations
- // Initalizations
- // Input
- // Process
- // Output
- cout << "This Program Automatically opens the superbowl.dat file. \nIt will then sort and analyze the information for you below: ";
- cout << endl;
- cout << left << "---------------------------------------------------" << endl;
- cout << left << setw(20) << "Winner" << " | " << setw(20) << "Loser" << " | "<< setw(20) << "Score" << endl;
- cout << left << "---------------------------------------------------" << endl;
- for(int i = 0; i < 47; i++)
- {
- cout << left << setw(20) << winner[i] << " | " << setw(20) << loser[i] << " | " << setw(20) << score[i] << endl;
- }
- cout << left << "---------------------------------------------------" << endl;
- cout <<"The Average Score is: " << average << endl;
- cout << left << "---------------------------------------------------" << endl;
- cout << "The Highests Scoring Game Was: " << endl;
- cout << winner[arrayPlace] << " Vs. " << loser[arrayPlace] << "\nWith the " << winner[arrayPlace] << " scoring: " << highScore << " Points To Win." << endl;
- cout << left << "---------------------------------------------------" << endl;
- cout << "The Lowest Scoring Game Was: " << endl;
- cout << winner[arrayPlace2] << " Vs. " << loser[arrayPlace2] << "\nWith the " << winner[arrayPlace2] << " scoring only: " << leastScore << " Points To Win." << endl;
- cout << left << "---------------------------------------------------" << endl;
- cout << "The Amount of Games That Scored More Than 40 Points is: " << amountAbove << endl;
- cout << left << "---------------------------------------------------" << endl;
- // Prolouge
- }
- int main()
- {
- // Declarations
- ifstream in;
- string winner[48] = { };
- string loser[48] = { };
- double score[48] = { };
- double highScore = 0.0;
- double leastScore = 0.0;
- double average = 0.0;
- int amountAbove = 0;
- int arrayPlace = 0;
- int arrayPlace2 = 0;
- // Initalizations
- // My variables are initalized above in the declarations
- // Input
- openFile(in);
- lines(in, winner, loser, score);
- // Process
- averageScores(score, average);
- highest(highScore, score, arrayPlace);
- least(leastScore, score, arrayPlace2, highScore);
- moreThan40(score, amountAbove);
- // Output
- output(winner, loser, score, average, highScore, arrayPlace, arrayPlace2, leastScore, amountAbove);
- // Prolouge
- in.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement