//Alessandro Iniguez CSC5 Chapter 11, P. 646, #6
//
/******************************************************************************
*
* SOCCER PLAYER
* _____________________________________________________________________________
* The program should keep 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 players 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
* playNum : players number
*
* OUTPUT
* Points : Scored goals
* Name : Players name
*
******************************************************************************/
#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 << "\nYou will need the following information.\n";
cout << "Pertaining to your Soccer Players.\n";
cout << "The Player's Names, Player's Numbers\n";
cout << "Finally you will need the Points Scored by Players.\n\n\n";
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\n";
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\n";
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:\n\n";
cout << " Name Number Score \n";
cout << "--------------------------------\n";
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 << "\n\nThe 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: ";
cout << players[maxIndex].playNum << endl;
return;
}