In the following C++ program, \"bb_teams\", add to the cout display another colu
ID: 3624750 • Letter: I
Question
In the following C++ program, "bb_teams", add to the cout display another column called "Rank" and display the rank of the team based on the win%
Here is the program. You also need the txt file "data2.txt" given below:
#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
using namespace std;
int main()
{
string team[10];
short wins[10];
short losses[10];
float winp[10];
float lossp[10];
ifstream fin ("data2.txt", ios::in);
cout << setw(10) << "Team" << setw(10) << "Wins" << setw(10) << "Losses" << setw(10) << "Win%" << setw(10) << "Loss%" << endl;
cout << setw(10) << "====" << setw(10) << "====" << setw(10) << "======" << setw(10) << "====" << setw(10) << "=====" << endl;
cout << fixed << setprecision(2) << endl;
for(short i=0;i<10;i++)
{
fin >> team[i] >> wins[i] >> losses[i];
winp[i]=wins[i]*100.00/(wins[i]+losses[i]);
lossp[i]=losses[i]*100.00/(wins[i]+losses[i]);
cout << setw(10) << team[i] << setw(10) << wins[i] << setw(10) << losses[i] << setw(10) << winp[i] << setw(10) << lossp[i] << endl;
}
return 0;
}
Here is the required data you need to create in a file in the C++ project for the ifstream fin: data2.txt
Knicks 74 80
Mavericks 6 60
Magic 88 53
Heat 53 42
Nets 17 87
Lakers 44 91
Celtics 93 92
Warriors 31 72
Cavaliers 85 54
Bulls 86 82
Explanation / Answer
please rate - thanks
#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
using namespace std;
int main()
{
string team[10];
short wins[10];
short losses[10];
float winp[10];
float lossp[10];
float rank[10],t;
ifstream fin ("data2.txt", ios::in);
cout << setw(10) << "Team" << setw(10) << "Wins" << setw(10) << "Losses" << setw(10) << "Win%" << setw(10) << "Loss%" << setw(10) << "Rank" << endl;
cout << setw(10) << "====" << setw(10) << "====" << setw(10) << "======" << setw(10) << "====" << setw(10) << "=====" << setw(10) << "=====" << endl;
cout << fixed << setprecision(2) << endl;
cout<<endl;
for(short i=0;i<10;i++)
{fin >> team[i] >> wins[i] >> losses[i];
winp[i]=wins[i]*100.00/(wins[i]+losses[i]);
lossp[i]=losses[i]*100.00/(wins[i]+losses[i]);
}
for(short i=0;i<10;i++)
rank[i]=winp[i];
for(short i=0;i<9;i++)
for(short j=i+1;j<10;j++)
if(rank[i]>rank[j])
{t=rank[i];
rank[i]=rank[j];
rank[j]=t;
}
for(short i=0;i<10;i++)
{
cout << setw(10) << team[i] << setw(10) << wins[i] << setw(10) << losses[i] << setw(10) << winp[i] << setw(10) << lossp[i] ;
for(short j=0;j<10;j++)
if(rank[j]==winp[i])
{cout<<setw(10)<<10-j<< endl;
j=10;
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.