Answer:
see explaination
Step-by-step explanation:
#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;
int getMax(int[],int);
int getMin(int[],int);
double getAvg(int[],int);
const int NUM_PLAYERS = 50;
int main(){
//ARRAYS TO STORE ALL THE INFORMATION OF THE PLAYERS FROM THE FILE
string names[NUM_PLAYERS];
int points[NUM_PLAYERS];
int rebound[NUM_PLAYERS];
int age[NUM_PLAYERS];
int steals[NUM_PLAYERS];
int blocks[NUM_PLAYERS];
int pf[NUM_PLAYERS];
int b, maxIndex, minIndex;
//OPENING THE FILE TO READ THE STATS FROM
ifstream infile;
infile.open("nbastats.txt");
if(!infile){
cout<<"File cannot be opened, please try again.\\";
return -1;
}
string temp;
//STORE THE TABLE HEADER IN TEMP
getline(infile,temp);
int count = 0;
//ITERATE THROUGH THE LINES AS LONG AS WE CAN GET NAMES OF THE PLAYERS
while(infile >> names[count]){
infile>>age[count]>>points[count]>>rebound[count]>>steals[count]>>blocks[count]>>pf[count];
count++;
}
//DISPLAYING THE CONTENTS OF THE FILE IN THE SAME FORMAT AS IN THE FILE
cout<<temp<<endl;
for(int i=0;i<count;i++){
/*
THIS IS THE LINE WHICH DISPLAYS THE OUTPUT IN THE REQUIRED FORMAT
*/
cout<<left<<setw(16)<<names[i]<<setw(8)<<age[i]<<setw(8)<<points[i]<<setw(8)<<rebound[i]<<setw(8)<<steals[i]<<setw(8)<<blocks[i]<<setw(8)<<pf[i]<<endl;
}
//DISPLAYING THE AVERAGE SCORE
cout<<"\\The average score is "<<getAvg(points,count)<<endl;
//DISPLAYING THE AVERAGE STEALS
cout<<"The average steals is "<<getAvg(steals,count)<<endl;
//DISPLAYING THE AVERAGE REBOUND
cout<<"The average rebound is "<<getAvg(rebound,count)<<endl;
//DISPLAYING THE MINIMUM SCORE
minIndex = getMin(points,count);
cout<<"The minimum score by "<<names[minIndex]<<" = "<<points[minIndex]<<endl;
//DISPLAYING THE MAXIMUM SCORE
maxIndex = getMax(points,count);
cout<<"The maximum score by "<<names[maxIndex]<<" = "<<points[maxIndex]<<endl;
return 0;
}
//FUNCTION TO CALCULATE THE AVERAGE SCORE GIVEN THE ARRAY OF SCORES
double getAvg(int points[],int size){
double sum = 0;
for(int i=0;i<size;i++){
sum = sum+points[i];
}
return double(sum/size);
}
//FUNCTION TO RETURN THE INDEX OF PLAYER WITH MINIMUM SCORE
int getMin(int points[], int size){
int minIndex,minScore;
minScore = points[0];
minIndex = 0;
for(int i=1;i<size;i++){
if(points[i] < minScore){
minScore = points[i];
minIndex = i;
}
}
return minIndex;
}
//FUNCTION TO RETURN THE INDEX OF PLAYER WITH MAXIMUM SCORE
int getMax(int points[], int size){
int maxIndex,maxScore;
maxScore = points[0];
maxIndex = 0;
for(int i=1;i<size;i++){
if(points[i] > maxScore){
maxScore = points[i];
maxIndex = i;
}
}
return maxIndex;
}