1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
zhenek [66]
3 years ago
9

• Write a program to find the maximum, minimum, and average score of players. The input to the program is a file containing play

er name and his score. For maximum and minimum scores, your program needs to output the name of the players along with their scores. Use functions to calculate average, min, and max scores. • The text file will just have players name and scores • nbaStatsFN.txt Sample Input/Output Here’s how the output should look formatted as in first few names: Oladipo 23 Richardson 10 Beal 14 George 16 Lillard 24 James 37 Young 9 Antetokounmpo 25 Bogdanovic 18 McCollum 34 Lowry 11 Prince 28 Hill 17 Middleton 19 Young 22 Westbrook 23 Adams 18 Satoransky 9 Dragic 9 Rozier 33 Hardaway 11
Computers and Technology
1 answer:
Gekata [30.6K]3 years ago
6 0

Answer:

see explaination

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.\n";

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<<"\nThe 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;

}

You might be interested in
What are the main approaches for dealing with deadlock?
alina1380 [7]

Answer:

Deadlock ignorance

Deadlock prevention

Deadlock avoidance

& Detection and recovery

Hope This Helps!!!

3 0
2 years ago
Choose the proper term to describe each of the following examples.
Lady_Fox [76]

Answer:first 1

Explanation:

4 0
2 years ago
30 point!! Looking at your Personal Fact Sheet, do you see any areas that may need improvement? In which areas do you have the m
Paul [167]
Can you please provide us with a photo of your personal fact sheet?
7 0
3 years ago
Read 2 more answers
I have a real struggle when it comes to working with strings, whether they're arrays or pointers to strings, and I'm lost cause
neonofarm [45]
In C, you deal with a string always via a pointer. The pointer by itself will not allocate memory for you, so you'll have to take care of that.

When you write char* s = "Hello world"; s will point to a "Hello world" buffer compiled into your code, called a string literal.

If you want to make a copy of that string, you'll have to provide a buffer, either through a char array or a malloc'ed bit of memory:

char myCopy[100];
strcpy(myCopy, s);

or 

char *myCopy;
myCopy = (char*)malloc( strlen(s) + 1 );
strcpy(myCopy, s);

The malloc'ed memory will have to be returned to the runtime at some point, otherwise you have a memory leak. The char array will live on the stack, and will be automatically discarded.

Not sure what else to write here to help you...
6 0
3 years ago
Advantages of bursaries??????
Alona [7]
A advantage of a bursary is that it is not a loan and therefore does not need to be paid back.
6 0
2 years ago
Other questions:
  • Bill needs to make a presentation in which he has to represent data in the form of a pyramid. Which feature or menu option of a
    14·1 answer
  • What does the Disk Defragmenter tool do?
    5·1 answer
  • What type of malicious procedure involves using sniffing tools to capture network communications to intercept confidential infor
    7·1 answer
  • Stuart wants to delete some text from a slide. What should Stuart do?
    8·1 answer
  • What values can represent a bit
    8·1 answer
  • A programmer needs to understand sequencing to determine whether the order of steps will affects the outcome of the program.
    11·1 answer
  • Do warnings ever expire?
    9·2 answers
  • Betty was sitting at a coffee shop reading her favorite book. She heard an explosion nearby. In a few, she could hear ambulance
    7·2 answers
  • What is one disadvantage people face without a checking account?
    12·1 answer
  • File names should be limited to 144 characters.<br><br> true or false
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!