Question
C++ code must be used. Do not touch main, that part is complete. My code is below. Write a program that stores the following data
C++ code must be used. Do not touch main, that part is complete. My code is below.
Write a program that stores 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 the team. When the program runs it should ask the user to enter the data for each player. It should then show a table that lists each player's number, name, and points scored. The program should also calculate and display the total points earned by the team. The number and name of the player, jersey number, and points of the player who has earned the most points should also be displayed.
Input Validation: Do not accept negative values for players' numbers or points scored. Do not accept a value greater than 99 for the players' numbers. Do not accept a value greater than 100 for the number of points scored.
Hints-
Create the struct in global space, not in a header file. (This makes it easier for me to grade.)
Assume there are no ties for high scores.
Use the start file to begin. Your job is to add the logic to the functions given the prototypes and the code provided in main.
~~~~ BELOW IS MY CODE ~~~~~ #include
using namespace std;
// Constant for the number of players const int NUM_PLAYERS = 12;
// Declaration of the Player structure struct Player { string name; // Player's name int number; // Player's number int points; // Points scored by the player }; // Function prototypes void getPlayerInfo(Player&); void showInfo(Player); int getTotalPoints(Player[], int); void showHighest(Player[], int); //*********************************************** // Function main * //*********************************************** int main() { // Array of Player structures Player team[NUM_PLAYERS];
// Loop counter int index; // Get each player's info. for (index = 0; index < 12; index++) { cout << " PLAYER #" << (index + 1) << " "; cout << "--------- "; getPlayerInfo(team[index]); cin.get(); } // Display the table headings. cout << setw(20) << left << " NAME"; cout << setw(10) << "NUMBER"; cout << setw(10) << "POINTS SCORED "; // Display the team info. for (index = 0; index < 12; index++) showInfo(team[index]);
// Display total points cout << "TOTAL POINTS: " << getTotalPoints(team, NUM_PLAYERS) << endl;
// Display the player scoring the most points. showHighest(team, NUM_PLAYERS); system("pause"); return 0; } //*********************************************** // Function getPlayer * // This function accepts a reference to a Player* // structure variable. The user is asked to * // enter the player's name, number, and the * // number of points scored. This data is stored * // in the reference parameter. * //*********************************************** void getPlayerInfo(Player& p) { cin >> p.number } //*********************************************** // Function showInfo * // This function displays the data in the Player* // structure variable passed into the parameter.* //*********************************************** void showInfo(Player p) { cout << p.name << p.number << p.points; } //*********************************************** // Function getTotalPoints * // This function accepts an array of Player * // structure variables as its argument. The * // function calculates and returns the total * // of all the players points in the array. * //*********************************************** int getTotalPoints(Player p[], int size) { // declare a local variable to accumulate for loop total = total + p[i].points
//return } //*********************************************** // Function showHighest * // This function accepts an array of Player * // structure variables. It displays the name * // of the player who scored the most points. * //*********************************************** void showHighest(Player p[], int size) { //display the name of the player }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started