In: Computer Science
Perform multiple sorts of printing in between sorts. Print a list of player names and total points, sorted from highest to lowest. Next, print a list of player names and rebounds, sorted from highest to lowest.
According to problem statement different functions are implemented for calculating the percentage of shooting, throw and for displaying the results in different ways as mentioned above.
#include<bits/stdc++.h>
using namespace std;
void shoot_percent(vector<float>
&s_percent,vector<int> &shots_made,vector<int>
&attempt){
for(int i=0;i<10;i++){
float tmp=(float)1.0*shots_made[i]/attempt[i];
s_percent[i]=tmp;
}
}
void throw_percent(vector<float>
&t_percent,vector<int>
&throw_attempt,vector<int> &throw_made)
{
for(int i=0;i<10;i++){
float tmp=(float)1.0*throw_made[i]/throw_attempt[i];
t_percent[i]=tmp;
}
}
void display(vector<string> &names,vector<float>
&s_percent,vector<float> &t_percent,vector<int>
&rebounds,
vector<int> &assists,vector<int>
&turnovers){
cout<<"The details of Players are "<<endl;
for(int i=0;i<10;i++){
cout<<names[i]<<" "<<s_percent[i]<<"
"<<t_percent[i]<<" "<<rebounds[i]<<"
"<<assists[i]<<" "<<turnovers[i];
cout<<endl;
}
}
void display_with_points(vector<string>
&names,vector<int>
&points,vector<pair<int,string>>
&display_points){
for(int i=0;i<10;i++){
display_points[i]={points[i],names[i]};
}
sort(display_points.rbegin(),display_points.rbegin());
for(int i=0;i<10;i++){
cout<<display_points[i].second<<"
"<<display_points[i].first<<endl;
}
}
void display_with_rebound(vector<string> &names,
vector<int>
&rebounds,vector<pair<int,string>>
&display_rebounds){
for(int i=0;i<10;i++){
display_rebounds[i]={rebounds[i],names[i]};
}
sort(display_rebounds.rbegin(),display_rebounds.rend());
for(int i=0;i<10;i++){
cout<<display_rebounds[i].second<<"
"<<display_rebounds[i].first<<endl;
}
}
int main(){
vector<string> names;
vector<int> points(10);
vector<int> attempt(10);
vector<int> shots_made(10);
vector<int> throw_attempt(10);
vector<int> throw_made(10);
vector<int> rebounds(10);
vector<int> assists(10);
vector<int> turnovers(10);
vector<float> s_percent(10);
vector<float> t_percent(10);
vector<pair<int,string>> display_points(10);
vector<pair<int,string>> display_rebounds(10);
cout<<"Enter the details of 10 Players";
cout<<endl;
for(int i=0;i<10;i++){
cout<<"Enter the details of player
"<<i+1<<endl;
cout<<"Enter the name ";cin>>names[i];
cout<<"Enter points ";cin>>points[i];
cout<<"Enter the shots attempted
";cin>>attempt[i];
cout<<"Enter the shots made ";cin>>shots_made[i];
cout<<"Enter the throw attempted
";cin>>throw_attempt[i];
cout<<"Enter the throw made ";cin>>throw_made[i];
cout<<"Enter number of rebounds
";cin>>rebounds[i];
cout<<"Enter number of assists ";cin>>assists[i];
cout<<"Enter the number of trurnovers
";cin>>turnovers[i];
}
shoot_percent(s_percent,shots_made,attempt);
throw_percent(t_percent,throw_made,throw_made);
display(names,s_percent,t_percent,rebounds,assists,turnovers);
display_with_points(names,points,display_points);
display_with_rebound(names,rebounds,display_rebounds);
}