Question

In: Computer Science

Write a program in C++ to keep statistics for a basketball team consisting of 10 players...

  1. Write a program in C++ to keep statistics for a basketball team consisting of 10 players using parallel arrays. The stats for each player should include the total points, shots attempted, shots made, free throw attempts, free throws made, rebounds, assists, and turnovers. Use functions to perform the following:
    1. Calculate the shooting percentage
    2. Calculate free throw percentage
    3. Print the player's names, shooting percentage, free throw percentage, rebounds, assists, and turnovers. After each player, use "endl" to skip to a new line.

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.

Solutions

Expert Solution

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);
  
  
  
  
}


Related Solutions

Soma recorded in the table the height of each player on the basketball team Basketball Players’...
Soma recorded in the table the height of each player on the basketball team Basketball Players’ Heights (in inches) 66 66 68 57 64 65 67 67 64 65 Construct a normal probability distribution curve for this population! Indicate the number for the mean, 1SD, 2SD and 3SD (both sides of the mea) (1+ 6*0.5=4p)
Write a program using c++. Write a program that uses a loop to keep asking the...
Write a program using c++. Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit. Your program must have (and use) at least four VALUE...
Two basketball players on a school team are working hard on consistency of their performance. In...
Two basketball players on a school team are working hard on consistency of their performance. In particular, they are hoping to bring down the variance of their scores. The coach believes that the players are not equally consistent in their games. Over a 10-game period, the scores of these two players are shown below. Assume that the two samples are drawn independently from normally distributed populations. (You may find it useful to reference the appropriate table: chi-square table or F...
In c++ Write a program that reads a string consisting of a positive integer or a...
In c++ Write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format. Use the STL stack
C++ this program will store roster and rating information for a soccer team. Coaches rate players...
C++ this program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team. (1) Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jersey numbers in one int vector and the ratings in another int vector. Output these vectors (i.e., output the roster). Ex: Enter player 1's jersey number: 84 Enter player 1's rating:...
Write a c++ program for the Sales Department to keep track of the monthly sales of...
Write a c++ program for the Sales Department to keep track of the monthly sales of its salespersons. The program shall perform the following tasks: Create a base class “Employees” with a protected variable “phone_no” Create a derived class “Sales” from the base class “Employees” with two public variables “emp_no” and “emp_name” Create a second level of derived class “Salesperson” from the derived class “Sales” with two public variables “location” and “monthly_sales” Create a function “employee_details” under the class “Salesperson”...
A bowling team consists of five players. Each player bowls three games. Write a program, in...
A bowling team consists of five players. Each player bowls three games. Write a program, in python, that uses a nested loop to enter each player’s name and individual scores (for three games). You will use one variable for the name and only one variable to enter the scores. Do not use score1, score2, and score3. Compute and display the bowler’s name and average score. Also, calculate and display the average team score. YOU MUST USE A NESTED LOOP FOR...
16#2 The following table provides the starting players of a basketball team and their heights Player...
16#2 The following table provides the starting players of a basketball team and their heights Player A B C D E Height (in.) 75 77 78 81 84 a. The population mean height of the five players is: 79 b. Find the sample means for samples of size 2. A, B: ?¯ = A, C: ?¯ = A, D: ?¯ = A, E: ?¯= B, C: ?¯ = B, D: ?¯ = B, E: ?¯ = C, D: ?¯= C,...
A basketball team has 5 players, 3 in ‘‘forward” positions (this includes the ‘‘center”) and 2...
A basketball team has 5 players, 3 in ‘‘forward” positions (this includes the ‘‘center”) and 2 in ‘‘guard” positions. How many ways are there to pick a team if there are 6 forwards, 4 guards, and 2 people who can play forward or guard?
C++ program, I'm a beginner so please make sure keep it simple Write a program to...
C++ program, I'm a beginner so please make sure keep it simple Write a program to read the input file, shown below and write out the output file shown below. Use only string objects and string functions to process the data. Do not use c-string functions or stringstream (or istringstream or ostringstream) class objects for your solution. Input File.txt: Cincinnati 27, Buffalo 24 Detroit 31, Cleveland 17 Kansas City 24, Oakland 7 Carolina 35, Minnesota 10 Pittsburgh 19, NY Jets...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT