Question

In: Computer Science

C++ Please. Break it down barney style if possible. Instructions Create a program to keep track...

C++ Please. Break it down barney style if possible.

Instructions

Create a program to keep track of the statistics for a kid’s soccer team. The program will have a structure that defines what data the program will collect for each of the players. The structure will keep the following data:

Players Name (string)

Players Jersey Number (integer)

Points scored by Player (integer)

The program will have an array of 12 players (use less for testing and development, use a constant for the size). Each element in the array is a different player on the team.

The program will ask the user to enter information for each player. The program will also display the team information in a table format. After the table, the total points scored by a team will be displayed.

The program will also determine which player scored the most points on the team.

Validation:

Do not accept negative value for player’s number

Do not accept negative value for player’s score

Required Methods:

void GetPlayerInfo(Player &);

void ShowPlayerInfo(const Player);

int GetTotalPoints(const Player[ ], int);

void ShowHighest(Player [ ], int)

Solutions

Expert Solution

/*C++ program that prompts user to enter the players information for the SIZE value.
Then print the player name, jersery number and score on console with neat table format.
Then find the total points of the players and player of highest score and player name .
Print the results on console output.*/

//main.cpp
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
//structure of Player
struct Player
{
   string name;
   int jerseyNumber;
   int score;
};
//function prototypes
void GetPlayerInfo(Player &);
void ShowPlayerInfo(const Player);
int GetTotalPoints(const Player[ ], int);
void ShowHighest(Player [ ], int);

int main()
{
   int index;
   //Change this constant SIZE TO 12 to read 12 player's name, jersey number and score values
  
   /*For sample input and output, only SIZE=3 taken to demonstrate the program*/
   const int SIZE=3;
   Player players[SIZE];


   //read player data
   for(index=0;index<SIZE;index++)
       GetPlayerInfo(players[index]);

   cout<<endl;
   //print heading
   cout<<left<<setw(20)<<"Name"
       <<setw(20)<<"Jersey#"
       <<setw(20)<<"Score"<<endl;

   for(index=0;index<SIZE;index++)
       ShowPlayerInfo(players[index]);

   //print highest score on console
   printf("Total points of players : %5d\n",GetTotalPoints(players,SIZE));
   ShowHighest(players,SIZE);

   system("pause");
   return 0;
}

/*Function ,ShowPlayerInfo that takes a Player object and
display the results on console output*/
void ShowPlayerInfo(const Player p)
{
   cout<<left<<setw(20)<<p.name
       <<setw(20)<<p.jerseyNumber
       <<setw(20)<<p.score<<endl;
}

/*Function to read player information*/
void GetPlayerInfo(Player &playerInfo)
{
   cout<<"Enter player's name : ";
   cin>>playerInfo.name;
   //Do not accept negative jersey number
   do
   {
       cout<<"Enter player's jersey number : ";
       cin>>playerInfo.jerseyNumber;

       if(playerInfo.jerseyNumber<0)
           cout<<"Error: Invalid jersey number ."<<endl;

   }while(playerInfo.jerseyNumber<0);

   //Do not accept negative score
   do
   {
       cout<<"Enter player's score : ";
       cin>>playerInfo.score;

       if(playerInfo.score<0)
           cout<<"Error: Invalid score ."<<endl;

   }while(playerInfo.score<0);
}

/*Function ,GetTotalPoints that takes Players array and its size as input
and then find the total points of score and return total score.*/
int GetTotalPoints(const Player players[ ], int size)
{
   int totalPoints=0;
   int index=0;
   for(index=0;index<size;index++)
       totalPoints+=players[index].score;

   return totalPoints;
}

/*Function, ShowHighest that takes Player array and its size as input
and then find the highest score value on console output.*/
void ShowHighest(Player players[ ], int size)
{
   //Assume that the first player's score is highest
   int highest=players[0].score;

   string playerName;
   //Assign player at index,0 name to playerName
   playerName=players[0].name;

   int index=0;
   for(index=0;index<size;index++)
   {
       //check if score at index is greater than highest value
       if(players[index].score>highest)
       {
           //Then, update the highest score and name values
           highest=players[index].score;
           playerName=players[index].name;
       }
   }
   //print highest score player and its score
   cout<<"Player's Name : "<<playerName<<endl;
   cout<<"Highest score : "<<highest<<endl;
}

Sample Output:


Related Solutions

how do I find the p-value? please break it down barney style
how do I find the p-value? please break it down barney style
Please be as discriptive as possible. (Break it down dummy style please) Regarding the posted article...
Please be as discriptive as possible. (Break it down dummy style please) Regarding the posted article “Hepatitis E vaccine debuts: Success of Chinese biotech partnership raises hopes for prevention of overlooked diseases” (Nature 10/29/2012): The workers made a recombinant subunit vaccine in E. coli host cells. Hepatitis E virus is a non-enveloped virus that contains an RNA genome and icosahedral capsid. Describe a stepwise process that could be used to develop and produce the vaccine. You have purified hepatitis E...
USE C++ and please keep program as simple as possible and also comment so it is...
USE C++ and please keep program as simple as possible and also comment so it is easy to understad Create a structure called time. Its three members, all type int, should be called hours, minutes, and seconds. Write a program that prompts the user to enter a time value in hours, minutes, and seconds. This should be in 12:59:59 format. This entire input should be assigned first to a string variable. Then the string should be tokenized thereby assigning the...
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”...
Accounting Program in c++ Write a class to keep track of a balance in a bank...
Accounting Program in c++ Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the interest rate to some initial values (with defaults of zero). The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or withdrawal (subtract from the balance). You should not...
You are going to create a console based program to keep track of a small business...
You are going to create a console based program to keep track of a small business that sells Doodads. First you will need to create a class Doodad that keeps track of two integers and two Strings. Next, create a constructor for the Doodad. Next, add getters and setters for each of the fields (two integers and two Strings). You need to use Doodad.java (see the starter code) Inside your main method ask the user to read in the two...
Using c++ Design a system to keep track of employee data. The system should keep track...
Using c++ Design a system to keep track of employee data. The system should keep track of an employee’s name, ID number and hourly pay rate in a class called Employee. You may also store any additional data you may need, (hint: you need something extra). This data is stored in a file (user selectable) with the id number, hourly pay rate, and the employee’s full name (example): 17 5.25 Daniel Katz 18 6.75 John F. Jones Start your main...
Create JAVA PROGRAM, and write comment for codes also. 3) You want to keep track of...
Create JAVA PROGRAM, and write comment for codes also. 3) You want to keep track of your progress towards running a 10K. There are two kinds of races - 5K and 10K. The program needs to ask what race was run and what the time was in seconds until the user quits. When they quit, display the average and best time for each type of race in minutes.
Create a C program that simulates time-sharing in the operating system. Please follow the instructions provided:...
Create a C program that simulates time-sharing in the operating system. Please follow the instructions provided: a) Use a circular queue. b) It is required that the process be inputted by the user. The user must input the process name and the duration in seconds, and for this simulation let the user input 5 processes. c) As this requires process name and duration, use an array of structures. d) To simulate time-sharing, following the algorithm presented below: d.1) Use the...
Use C++ please You will be building a linked list. Make sure to keep track of...
Use C++ please You will be building a linked list. Make sure to keep track of both the head and tail nodes. (1) Create three files to submit. PlaylistNode.h - Class declaration PlaylistNode.cpp - Class definition main.cpp - main() function Build the PlaylistNode class per the following specifications. Note: Some functions can initially be function stubs (empty functions), to be completed in later steps. Default constructor (1 pt) Parameterized constructor (1 pt) Public member functions InsertAfter() - Mutator (1 pt)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT