Question

A competition takes place for the development of a new functionality that will be added on...

A competition takes place for the development of a new functionality that will be added on the NBA daily stats. This new functionality will show the player with the maximum ratio of points per minute.

Develop a program in C++ that prompts the user to enter data for a number of NBA players and then outputs the player(s) with the maximum ratio of points per minute.

You can store the players entered by the user in an array of structs with dynamic array of structs.

Sample prompts:

How many players will you enter? 2

Enter first name: LeBron Enter last name: James Enter points: 30.5
Enter minutes: 37.8

Enter first name: Giannis Enter last name: Antetokounmpo Enter points: 23.5
Enter minutes: 34.8

The maximum ratio of points per minute is: 0.81
Players with maximum ratio of points per minute: Lebron James

*Must declare constant integer, Assume each data entered by user won't contain any spaces, program must stop prompting for further input if the max number of players is reached, Data type for points should be double, have three functions (1. read players' data into an array, 2. finx max radio of points per minute 3. print names of players with max ratio)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

#include<string>

#include<iomanip>

using namespace std;

int number;

double ratio[100];

double maximum;

int index;

struct players{

//Using Structure to save players

string fname,lname;

double points,minutes;

};

void ReadPlayers(players *arr) {

    for(int i=0;i<number;i++){

    cout<<"\nEnter first name: ";

    cin>>arr[i].fname;

    cout<<"Enter last name: ";

    cin>>arr[i].lname;

    cout<<"Enter points: ";

    cin>>arr[i].points;

    cout<<"Enter minutes: ";

    cin>>arr[i].minutes;

    ratio[i]=arr[i].points/arr[i].minutes;

    }

}

void FindMaximumRatio() {

    maximum=ratio[0];

    index=0;

    for(int i=1;i<number;i++){

    if(ratio[i]>maximum){

    maximum=ratio[i];

    index=i;

        }

    }

    cout<<"\nThe maximum ratio of points per minute is:"<<fixed<<setprecision(2)<<maximum;

}

void PrintResult(players *arr){

    cout<<"\nPlayers with maximum ratio of points per minute: "<<arr[index].fname<<" "<<arr[index].lname; // printing name of the player holding maximum ratio

}

//Main Function to call all the other functions

int main(){

    cout<<"How many players will you enter? ";

    cin>>number;

    players *array=new players[number];

    ReadPlayers(array);

    FindMaximumRatio();

    PrintResult(array);

    delete[] array;

    return 0;

}

Output:

Add a comment
Know the answer?
Add Answer to:
A competition takes place for the development of a new functionality that will be added on...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C Program This program will store the roster and rating information for a soccer team. There w...

    In C Program This program will store the roster and rating information for a soccer team. There will be 3 pieces of information about each player: Name: string, 1-100 characters (nickname or first name only, NO SPACES) Jersey Number: integer, 1-99 (these must be unique) Rating: double, 0.0-100.0 You must create a struct called "playData" to hold all the information defined above for a single player. You must use an array of your structs to to store this information. You...

  • This program will ask the user to enter a number of players, then ask the user...

    This program will ask the user to enter a number of players, then ask the user for each player's name and score. Once all of the players have been entered, the program will display a bar chart with each of their scores scaled as a percentage of the maximum score entered. See below for details on exactly how this should work - an example transcript of how the program should work is shown below (remember that values entered by the...

  • In C++: Functions to include: editPlayer: is a void fn, which takes an array of playerType...

    In C++: Functions to include: editPlayer: is a void fn, which takes an array of playerType and calls lookUpPlayer which returns the index of the target (-1 if not found). If found allows the user to edit any of the data members of the player via a menu system. lookUpPlayer: is a int fn, which takes an array of playerTypes, prompts the user for the name of the player and attempts to find them. If found, prints message "found" and...

  • C++: Array of contact info Design a contact struct, that takes your phone struct and address...

    C++: Array of contact info Design a contact struct, that takes your phone struct and address struct along with a c string for a name to create a record of contact information. ( C++: Design a Struct Design two structs address and phone Address has the following attributes: street address, city name, state code, zip code. phone has 3 numbers: area code, prefix and suffix test these by writing a program that creates one of each and fills them with...

  • Need done in C++ Can not get my code to properly display output. Instructions below. The...

    Need done in C++ Can not get my code to properly display output. Instructions below. The code compiles but output is very off. Write a program that scores the following data about a soccer player in a structure:            Player’s Name            Player’s Number            Points Scored by Player      The program should keep an array of 12 of these structures. Each element is for a different player on a team. When the program runs, it should ask the user...

  • In this project, you will use functions and dictionaries to track basketball players and their respective...

    In this project, you will use functions and dictionaries to track basketball players and their respective points, then display statistics of points made. You will need three functions as follows: def freeThrowMade(playerDictionary, playerName) - this function will add 1 point to the player's total score def twoPointMade(playerDictionary, playerName) - this function will add 2 points to the player's total score def threePointMade(playerDictionary, playerName) - this function will add 3 points to the player's total score Each of these functions has...

  • 1. Write a C programme by using visual Studio: a) Write a function with parameters that...

    1. Write a C programme by using visual Studio: a) Write a function with parameters that returen the largest of three integer arguments. So users could call your function (name: max3) to output the maximum of three input values. b) Make a function outside of the main routine. And in the main routine, please call this function and print the harmonic mean. The harmonic mean of two numbers is obtained by taking the inverses of the two numbers, averaging them,...

  • Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the...

    Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the original high score program,: Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look exactly like this: Enter the name for score #1: Suzy Enter the score for...

  • This java assignment will give you practice with classes, methods, and arrays. Part 1: Player Class...

    This java assignment will give you practice with classes, methods, and arrays. Part 1: Player Class Write a class named Player that stores a player’s name and the player’s high score. A player is described by:  player’s name  player’s high score In your class, include:  instance data variables  two constructors  getters and setters  include appropriate value checks when applicable  a toString method Part 2: PlayersList Class Write a class that manages a list...

  • C++ Single Dimensional Arrays

    Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes numeric scores for a class. The program prompts the users to enter the class size (number of students) to create a single-dimensional array of that size to store the scores. The program prompts the user to enter a valid integer score (between 0 and 100) for each student. The program validates entered scores, rejects invalid scores, and stores only valid scores in the array.  The program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT