Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please write a C++ program that will process the result of the super bowls. You

ID: 3572973 • Letter: P

Question

Please write a C++ program that will process the result of the super bowls. You will be using a data file called superbowl.dat. There will be three lines for each super bowl. THE DATA IS LISTED BELOW The first line will contain the name of the winning team, the second line will contain the name of the losing team and the third line will contain the number of points scored by the winning team. You are to read from the file and place the values in parallel arrays. There have been 47 super bowls. The program should read into the arrays. The program should then print out the arrays side by side in neat, labeled columns. It should print out the average number of points scored by the winning team, the number of winning teams that scored more than 40 points, the winner and loser in the super bowl where the most points were scored and the winner and the loser in the super bowl where the least points were scored. Each calculation should have a function of its own. NO output should be done in functions that do calculations. All output should be done in one output function. Remember to always pass the number of elements in the array with the array to functions. Create functions as described above (six total functions)! 1. read the datafile 2. calculate average points 3. calculate number of games with over 40 points 4. find winner and loser in game with most points 5. find winner and loser in game with least points 6. one function to output all results Superbowl.dat: Packers Chiefs 35 Packers Raiders 33 Jets Colts 16 Chiefs Vikings 23 Colts Cowboys 16 Cowboys Dolphins 24 Dolphins Redskins 14 Dolphins Vikings 24 Steelers Vikings 16 Steelers Cowboys 21 Raiders Vikings 32 Cowboys Broncos 27 Steelers Vikings 35 Steelers Rams 31 Raiders Eagles 27 49ers Bengals 26 Redskins Dolphins 27 Raiders Redskings 38 49ers Dolphins 38 Bears Patriots 46 Giants Broncos 39 Redskins Broncos 42 49ers Bengals 20 49ers Broncos 55 Giants Bills 20 Redskins Bills 37 Cowboys Bills 52 Cowboys Bills 30 49ers Chargers 49 Cowboys Steelers 27 Packers Patriots 35 Broncos Packers 31 Broncos Falcons 34 Rams Titans 23 Ravens Giants 34 Patriots rams 20 Buccaneers Raiders 48 Patriots Panthers 32 Patriots Eagles 24 Steelers Seahawks 21 Colts Bears 29 Giants Patriots 17 Steelers Cardinals 27 Saints Colts 31 Packers Steelers 31 Giants Patriots 21 Ravens 49ers 34 Seahawks Broncos 43 Patriots Seahawks 28 Broncos Panthers 24

Explanation / Answer

#include<iostream>
#include <fstream>
#include <iomanip>
//For alignment
using std::right;
using std::left;
using namespace std;
//Class Super Bowls
class SuperBowls
{
public:
char Winner[50][50], Losing[50][50];
int score[50], co, wc, lc, sc;
//Method prototype
void Read(char [][50], char [][50], int []);
void Show(char [][50], char [][50], int []);
int averageScoreWin(int [], int);
int countWin(int [], int);
int maxWin(int [], int);
int minWin(int [], int);
int maxLos(int [], int);
int minLos(int [], int);
};
//Returns Maximum Loss
int SuperBowls::maxLos(int score[], int lc)
{
int big = score[1], x = 1;
for(int c = 0; c < lc; c++, x+= 2)
if(score[x] > big)
big = score[x];
return big;
}
//Returns Minimum Loss
int SuperBowls::minLos(int score[], int lc)
{
int small = score[1], x = 1;
for(int c = 0; c < lc; c++, x+= 2)
if(score[x] < small)
small = score[x];
return small;
}
//Returns Maximum Win
int SuperBowls::minWin(int score[], int wc)
{
int small = score[0], x = 0;
for(int c = 0; c < wc; c++, x+= 2)
if(score[x] < small)
small = score[x];
return small;
}
//Returns Minimum Loss
int SuperBowls::maxWin(int score[], int wc)
{
int big = score[0], x = 0;
for(int c = 0; c < wc; c++, x+= 2)
if(score[x] > big)
big = score[x];
return big;
}
//Returns number of win greater than 40
int SuperBowls::countWin(int score[], int wc)
{
int counter = 0, x = 0;
for(int c = 0; c < wc; c++, x+=2)
if(score[x] > 40)
counter++;
return counter;
}
//Returns average score for winer
int SuperBowls::averageScoreWin(int score[], int wc)
{
float tot = 0, avg;
int x = 0;
for(int c = 0; c < wc; c++, x+= 2)
tot += score[x];
avg = tot / wc;
cout<<" Count win: "<<wc<< " Total: "<<tot;
return avg;
}
//Reads data from file
void SuperBowls::Read(char Winner[][50], char Losing[][50], int score[])
{
ifstream fin; //Read file
fin.open("Superbowl.txt"); //Open Superbowl.dat file for reading
co = 0;
wc = lc = sc = 0;
//Checks whether file can be opened or not
if (fin.is_open())
{
//Till end of file
while (!fin.eof()) //Checks end of file
{
if(co % 2 == 0 )
{
fin>>Winner[wc]>>score[sc]; //Reads the first data
wc++; sc++;
}
else
{
fin>>Losing[lc]>>score[sc];
lc++; sc++;
}
co++;
}
}
else
cout<<"Error: In open file";
}
//Displays the information
void SuperBowls::Show(char Winner[][50], char Losing[][50], int score[])
{
cout<<"WINNER ";
cout<<"Sl. No. Name Score ";
int x = 0;
for(int c = 0; c < wc; c++, x+=2)
{
cout<<c<<") "<<left<<setw(15)<<Winner[c]<<right<<setw(15)<<score[x]<<endl;
}
cout<<" LOSER ";
cout<<"Sl. No. Name Score ";
x = 1;
for(int c = 0; c < lc; c++, x+= 2)
{
cout<<c<<") "<<left<<setw(15)<<Losing[c]<<right<<setw(10)<<score[x]<<endl;
}
cout<<" Average Score by Wining Team: "<<averageScoreWin(score, wc);
cout<<" Number of Wining Team Score More Than 40: "<<countWin(score, wc);
cout<<" Maximum Score by a Wining Team: "<<maxWin(score, wc);
cout<<" Minimum Score by a Wining Team: "<<minWin(score, wc);
cout<<" Maximum Score by a Losing Team: "<<maxLos(score, lc);
cout<<" Minimum Score by a Losing Team: "<<minLos(score, lc);
}

int main()
{
//Creates an object of class Super Bowls
SuperBowls sw;
sw.Read(sw.Winner, sw.Losing, sw.score);
sw.Show(sw.Winner, sw.Losing, sw.score);
}

Output:

WINNER

Sl. No. Name Score
0) PackersChiefs 35
1) JetsColts 16
2) ColtsCowboys 16
3) DolphinsRedskins 14
4) SteelersVikings 16
5) RaidersVikings 32
6) SteelersVikings 35
7) RaidersEagles 27
8) RedskinsDolphins 27
9) 49ersDolphins 38
10) GiantsBroncos 39
11) 49ersBengals 20
12) GiantsBills 20
13) CowboysBills 52
14) 49ersChargers 49
15) PackersPatriots 35
16) BroncosFalcons 34
17) RavensGiants 34
18) BuccaneersRaiders 48
19) PatriotsEagles 24
20) ColtsBears 29
21) SteelersCardinals 27
22) PackersSteelers 31
23) Ravens49ers 34
24) PatriotsSeahawks 28

LOSER

Sl. No. Name Score
0) PackersRaiders 33
1) ChiefsVikings 23
2) CowboysDolphins 24
3) DolphinsVikings 24
4) SteelersCowboys 21
5) CowboysBroncos 27
6) SteelersRams 31
7) 49ersBengals 26
8) RaidersRedskings 38
9) BearsPatriots 46
10) RedskinsBroncos 42
11) 49ersBroncos 55
12) RedskinsBills 37
13) CowboysBills 30
14) CowboysSteelers 27
15) BroncosPackers 31
16) RamsTitans 23
17) Patriotsrams 20
18) PatriotsPanthers 32
19) SteelersSeahawks 21
20) GiantsPatriots 17
21) SaintsColts 31
22) GiantsPatriots 21
23) SeahawksBroncos 43
24) BroncosPanthers 24

Count win: 25 Total: 760
Average Score by Wining Team: 30
Number of Wining Team Score More Than 40: 3
Maximum Score by a Wining Team: 52
Minimum Score by a Wining Team: 14
Maximum Score by a Losing Team: 55
Minimum Score by a Losing Team: 17