//Andrew Alspaugh CS1A Chapter 11. P.646. #6
//
/*****************************************************************************
Soccer Scores
____________________________________________________________________________
This program stores and manages data for a soccer team. It asks the user to
enter each player's name, number, and points scored. The program displays a
table listing all players with their numbers and points, calculates the total
points scored by the team, and identifies the player with the most points.
____________________________________________________________________________
//Data Dictionary
//Inputs
const int teamSize = 12;
Player team[teamSize]; // array to store 12 player structures
//Outputs
int totalPoints = 0; // total points scored by the team
int maxPoints = -1; // highest points scored by a player
int topPlayerIndex = 0; // index of the top scoring player
*****************************************************************************/
#include <iostream>
#include <string>
using namespace std;
struct Player
{
string name;
int number;
int points;
};
int main()
{
//DATA DICTIONARY
const int teamSize = 12;
Player team[teamSize];
int totalPoints = 0;
int maxPoints = -1;
int topPlayerIndex = 0;
//INPUT
// Input data for each player
for(int i = 0; i < teamSize; i++)
{
cout << "Enter name of player " << i + 1 << " :" << endl;
cin >> ws; // Consume any leftover newline characters
getline(cin, team[i].name);
cout << "Enter number of player " << i + 1 << " :" << endl;
cin >> team[i].number;
cout << "Enter points scored by player " << i + 1 << " :" << endl;
cin >> team[i].points;
totalPoints += team[i].points;
if(team[i].points > maxPoints)
{
maxPoints = team[i].points;
topPlayerIndex = i;
}
}
//OUTPUT
// Display table
cout << endl;
cout << "Player Number\tName\t\tPoints" << endl;
cout << "----------------------------------------" << endl;
for(int i = 0; i < teamSize; i++)
{
cout << team[i].number << "\t\t" << team[i].name << "\t\t" << team[i].points << endl;
}
// Display totals and top scorer
cout << endl;
cout << "Total points by the team: " << totalPoints << endl;
cout << "Top scorer: " << team[topPlayerIndex].name
<< " (Number: " << team[topPlayerIndex].number
<< ", Points: " << team[topPlayerIndex].points << ")" << endl;
return 0;
}