fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5. // OrinTill Qimid CS1A Chapter 4, P. 294, 10
  6. //
  7. // /**************************************************************
  8. // * Entry for Players.
  9. // *
  10. // * ____________________________________________________________
  11. // * This program will display player stats.
  12. // * ____________________________________________________________
  13. // * INPUT
  14. // * Player stats
  15. // * OUTPUT
  16. // * Displaying player stats.
  17. // **************************************************************/
  18.  
  19. // Define the MonthlyBudget structure
  20. struct Player {
  21. string name;
  22. int number;
  23. int points;
  24. };
  25.  
  26. int main() {
  27. const int TEAM_SIZE = 12;
  28. vector<Player> team(TEAM_SIZE);
  29. int totalPoints = 0;
  30. Player topPlayer;
  31. topPlayer.points = -1; // Initialize with a value lower than any expected score
  32.  
  33. // Input player details
  34. for (int i = 0; i < TEAM_SIZE; ++i) {
  35. cout << "Enter details for player " << (i + 1) << ":\n";
  36. cout << "Name: ";
  37. cin >> team[i].name;
  38. cout << "Number: ";
  39. cin >> team[i].number;
  40. cout << "Points Scored: ";
  41. cin >> team[i].points;
  42. cout << "\n";
  43.  
  44. totalPoints += team[i].points;
  45. if (team[i].points > topPlayer.points) {
  46. topPlayer = team[i];
  47. }
  48. }
  49.  
  50. // Display player details
  51. cout << "\nTeam Players:\n";
  52. cout << "Number\tName\tPoints\n";
  53. for (const auto& player : team) {
  54. cout << player.number << "\t" << player.name << "\t" << player.points << "\n";
  55. }
  56.  
  57. // Display total points and top player
  58. cout << "\nTotal points scored by the team: " << totalPoints << "\n";
  59. cout << "Top player: " << topPlayer.name << " (Number: " << topPlayer.number << ") with " << topPlayer.points << " points.\n";
  60.  
  61. return 0;
  62. }
  63.  
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
Enter details for player 1:
Name: Number: Points Scored: 
Enter details for player 2:
Name: Number: Points Scored: 
Enter details for player 3:
Name: Number: Points Scored: 
Enter details for player 4:
Name: Number: Points Scored: 
Enter details for player 5:
Name: Number: Points Scored: 
Enter details for player 6:
Name: Number: Points Scored: 
Enter details for player 7:
Name: Number: Points Scored: 
Enter details for player 8:
Name: Number: Points Scored: 
Enter details for player 9:
Name: Number: Points Scored: 
Enter details for player 10:
Name: Number: Points Scored: 
Enter details for player 11:
Name: Number: Points Scored: 
Enter details for player 12:
Name: Number: Points Scored: 

Team Players:
Number	Name	Points
0		0
0		0
0		0
0		0
0		0
0		0
0		0
0		0
0		0
0		0
0		0
0		0

Total points scored by the team: 0
Top player:  (Number: 0) with 0 points.