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

Write in C++ Write a program that stores the following data about a soccer playe

ID: 3573481 • Letter: W

Question

Write in C++

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 a 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 who has earned the most points should also be displayed. Input Validation Input Validation: Do not accept negative values for players' numbers or points scored. If the user types in an incorrect value re-prompt them to enter an acceptable value until they do. Sample Output You are free to format this program as you wish as long as it follows good programming principles.

Explanation / Answer

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
struct Player
{
   char name[100];
   int player_num;
   int points;
};

int main(int argc, char** argv) {
   int error=1;
   int highest_scorer=0;
   struct Player players[12];
   int i;
   cout<<" Enter Details i.e player name,player number and points for 12 players ";
  
   for(i=0;i<12;i++)
   {
      
       cout<<" enter name:";
   cin>>players[i].name;
   while(error==1)
   {
       cout<<" enter player number:";
   cin>>players[i].player_num;
   if(players[i].player_num<0)
   {
       cout<<" please enter a positive value for player number ";
       continue;
   }
   cout<<" enter player points:";
   cin>>players[i].points;
       if(players[i].points<0)
   {
       cout<<" please enter a positive value for player points ";
       continue;
   }
   cin.clear();
   error=0;
   }  
   error=1;
  
   }
   //Display each players details
   cout<<" ----------------------------------- ";
   cout<<" player name player number points ";
   for(i=0;i<12;i++)
   {
       cout<<i<<" "<<players[i].name<<" "<<players[i].player_num<<" "<<players[i].points<<endl;
   }
   //Calculate the total points earned by team
   int total_points=0;
   for(i=0;i<12;i++)
   total_points+=players[i].points;
   //find the player with maximum points
   for(i=0;i<12;i++)
   {
       if(players[i].points>players[highest_scorer].points)
       highest_scorer=i;
   }
   cout<<" Total points earned by team="<<total_points<<endl;
   cout<<" Player with HIghest score is name:";
   cout<<players[highest_scorer].name<<" score:"<<players[highest_scorer].points<<endl;
   return 0;
}

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