Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that stores the following data about a soccer player in a struct

ID: 3696308 • Letter: W

Question

Write a program that stores the following data about a soccer player in a structure named Player. (c++ program)

name: a string that stores player’s name

number: an integer that stores player’s number

address: a string that stores player’s address (3rd field in the given file)

city: a string that stores player’s city

state: a string that stores player’s state

zip: an integer that stores player’s ZIP code

phone: an integer that stores player’s phone number

date: an integer that stores player’s contract date

points: an integer that stores points scored by player

The program should use an array of 10 structures named team. Each element is for a different player on the team. The program should have a menu-driven user interface containing the following choices. Write a function for each step.

readData. Read players’ info from file team.txt to the array.

displayData. Display all the data stored in the array.

getAverage. Calculate and display the average of points earned by the team members.

getHighest. Display (print) all the info of the player who has earned the most points.

getTarget. Return (by references) all the info of the player whose number is num.

Function getTarget should accept an array as its first argument and an integer as its second argument. The second argument should be the number of target player. The function should return all the info of the first occurrence of the given number. Use references to return all the player’s info fields.

team.txt =

Explanation / Answer

Here is the cpp program with the given requirements for the soccer player.

it asks user to enter the players information and based on that calculates the highest and lowest scores of the player and the team.

save the program using suitable name and run in the linux environment

----------------------------------------------------------------------------------------------------------------------------------------------------

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;


const int SIZE = 50;
struct Player
{
   char name[SIZE]; //Player's Name
   int playNum; //Player's Number
   int Points; //Point's Scored
};

const int NUM_PLAYERS = 3; //Number of Players
// Dynamically allocate the memory needed.
Player *players = new Player[NUM_PLAYERS]; //Array of structures
int total = 0;

void getPlayerInfo(Player &);
void showInfo(Player);
int getTotalPoints(Player[], int);
void showHighest(Player[], int);

int main()
{
   getPlayerInfo(*players);
   getTotalPoints(players,total);
   showInfo(*players);

}

void getPlayerInfo(Player&)
{
   int index;
  

   // Get Player data.
   cout << " You will need the following information. ";
   cout << "Pertaining to your Soccer Players. ";
   cout << "The Player's Names, Player's Numbers ";
   cout << "Finally you will need the Points Scored by Players. ";
   for (index = 0; index < NUM_PLAYERS; index++)
   {
       cout << "Please enter the Player's Name: ";
       cin.getline(players[index].name, 50);
       cout << "Please enter the Player's Number: ";
       (cin >> players[index].playNum).get();

       //To test my values for zero, negative
       while (players[index].playNum <= 0)
       {
           cout << "Zero or negative numbers not allowed ";
           cout << "Please enter the Player's Number: ";
           (cin >> players[index].playNum).get();

       }
       cout << "Please enter the Points Scored by the Player: ";
       (cin >> players[index].Points).get();

       //To test my values for zero, negative.
       while (players[index].Points < 0)
       {
           cout << "Zero or negative numbers not allowed ";
           cout << "Please enter the Points Scored by the Player: ";
           (cin >> players[index].Points).get();
       }
       cout << endl << endl;
   }
   return;
}
int getTotalPoints(Player[], int)
{
   int index;
   int total = 0;
   //Calculate the total points
   for (index = 0; index < NUM_PLAYERS; index++)
   {
       total += players[index].Points;
   }
       int TotalPoints(int *, int);
  
   return total;
}
void showInfo(Player)
{
   int TotalPoints = 0;
   int index = 0;
   //Display the players data
   cout << "Here is the players data: ";
   cout << " Name Number Score   ";
   cout << "-------------------------------- ";

   for (index = 0; index < NUM_PLAYERS; index++)
   {
       cout << setw(8) << players[index].name;
       cout << setw(8) << players[index].playNum;
       cout << setw(8) << players[index].Points << endl;
   }
//Display the results of the total points.
   cout << " The total of points scored by the team are: ";
   cout << TotalPoints << endl;

   //To get the player with most points

   int max = players[0].Points;
   int maxIndex = 0;
   for (int index = 0; index < 12; index++)
   {
       if (players[index].Points > max)
       {
           max = players[index].Points;
           maxIndex = index;
       }
  
   }
   cout << "highest score by: " << players[maxIndex].name << " number: " << players[maxIndex].playNum << endl;
   return;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote