Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.27 KB | None | 0 0
  1. // Deven Pace Project 4
  2. // start
  3. // Create structure for players name, jersey number, and points Scored
  4. // declare methods used in the program.
  5. // the program must hold 12 players, so the int size should be 12.
  6. // create array that holds player information.
  7. // create headings for program.
  8. // needs to show total points scored.
  9. // create funciton that calls for players information
  10. // if jersey or points scored is less than 0 make a loop to have user input a positive number
  11. // create display of players name, jersey number, and points scored (adjust the setw to look right)
  12. // use function to calculate total points and store in array to determine who scores the highest pointsScored
  13. // each player starts at 0 points, so make a algortithm to calculate total points
  14. // use funciton to show the highest points scored by a player. Needs to be stored into pointsScored playerInfoArr
  15. // print player who scored the most points.
  16. // end
  17.  
  18. //notes
  19. // use a smaller number of players to test program. Remember to set size to 12 when completed.
  20. // must not accept negative values so write the for statement for the jersey number nand player score
  21. // remember to see why playerInfoArr[size] is not being called.
  22. // find the correct number for setw so program looks correct.
  23. // it doesnt show showHighest function. see why.
  24.  
  25. #include <string>
  26. #include <iomanip>
  27. #include <iostream>
  28. using namespace std;
  29.  
  30. //----------------------------------------------------------------------------//
  31.  
  32. //player st ruct
  33. struct Player
  34. {
  35. string playerName; //String used for storing player name
  36. int playerJerseyNumber; //int to keep player's jersey number
  37. int pointsScored; //int to keep player's points scored
  38. };
  39.  
  40. // dec methods
  41. void GetPlayerInfo(Player &); // Call function to gather player information
  42. void ShowPlayerInfo(const Player); // Call function to show player information
  43. int GetTotalPoints(const Player[], int); // Call function to find total points
  44. void ShowHighest(Player[], int); // Call function to show highest points
  45. //----------------------------------------------------------------------------//
  46.  
  47. int main()
  48. {
  49. int size = 12; //Size is the int that will store how many players there will be in the array.
  50. Player playerInfoArr[size]; //creating array that will store player info
  51. for (int x = 0; x < size; x++)
  52. {
  53. GetPlayerInfo(playerInfoArr[x]); //call function to gather player information
  54. }
  55. cout << left << setw(20) << "Name" << setw(20) << "Jersey Number" << setw(20) << "Points Scored" << endl; //heading to show player name, jersey number, and points scored (mess with the size, it isnt right.)
  56.  
  57. for (int x = 0; x < size; x++) //loop to show details about each player.
  58. {
  59. ShowPlayerInfo(playerInfoArr[x]); //calling the function to show the information of each player
  60. }
  61.  
  62. int total = GetTotalPoints(playerInfoArr, size); //calling function to gather total points scored
  63. cout << "Total Points Scored: " << total << endl; //printing points scored.
  64.  
  65. ShowHighest(playerInfoArr,size); //will call function to show which player had the highest score.
  66.  
  67. system("pause");
  68. return 0;
  69. }
  70.  
  71. //----------------------------------------------------------------------------//
  72. void GetPlayerInfo(Player &player) //Function to obtain player information
  73. {
  74. int number, points; //variables for jersey number and points scored
  75.  
  76. // Entering player name
  77. cout << "Enter the players name: "; //Asking user for player name
  78. cin >> player.playerName; //Assigns a name into the string
  79.  
  80. //Entering players jersey number.
  81. cout << "Enter players number: "; //Asking user for players number
  82. cin >> number; //input of players number
  83. while (number < 0) //User can't type a number lower than 0. This while loop assures that.
  84. {
  85. cout << "Must use a number equal or higher than zero!"; //Message if user inputs number less than 0
  86. cin >> number; //Users input
  87. }
  88. player.playerJerseyNumber = number; //Assigns player with jersey number
  89.  
  90. //Entering player pointsScored
  91. cout << "Enter players points scored: "; //Asking user for player point scored
  92. cin >> points; //User input of points scored
  93. while (points < 0) //User can't type a number lower than 0.
  94. {
  95. cout << "Must use a number equal or higher than zero!";//Message if user inputs number less than 0
  96. cin >> points;// User input
  97. }
  98. player.pointsScored = points; //Assigns players points scored.
  99. }
  100. //----------------------------------------------------------------------------//
  101.  
  102. void ShowPlayerInfo(const Player player) //Function to show player details.
  103. {
  104. cout << setw(20) << player.playerName << setw(20) << player.playerJerseyNumber << setw(20) << player.pointsScored << endl; //output of each players information //used setw to assure the display was easy to read
  105. }
  106. //----------------------------------------------------------------------------//
  107.  
  108. int GetTotalPoints(const Player playerInfoArr[], int size) //function to calculate total points
  109. {
  110. int sum = 0; //each player will start out at 0, the integer will increase per points scored
  111. for(int x = 0; x < size; x++) //loop to add points to the total points scored
  112. {
  113. sum += playerInfoArr[x].pointsScored; //algorithm to store points into array
  114. }
  115. return sum; //returns total points scored
  116. }
  117. //----------------------------------------------------------------------------//
  118.  
  119. void ShowHighest(Player playerInfoArr[], int size) //showing highest points scored
  120. {
  121. int playerPoints = playerInfoArr[0].pointsScored; //I set the points per player at 0, will increase if the player scores more than 0
  122. int playerPointsMax = 0; //will store player with highest points
  123. for(int x = 1; x < size; x++) //loop that determines who scores the most points
  124. {
  125. if(playerPoints < playerInfoArr[x].pointsScored)
  126. {
  127. playerPoints = playerInfoArr[x].pointsScored;
  128. playerPointsMax = x;
  129. }
  130. }
  131. Player highPoint = playerInfoArr[playerPointsMax]; //gets players points from maxpointint
  132. cout << "The player who scored the most points is: " << highPoint.playerName << endl; //printing the player with highest points
  133. cout << "They scored: " << highPoint.pointsScored << " total points." << endl; // printing total points scored
  134. }
  135. //----------------------------------------------------------------------------//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement