3 questions Use the following class declaration in the next problems struct Play
ID: 3714902 • Letter: 3
Question
3 questions
Use the following class declaration in the next problems struct Player string name int points class Game Private: Player players/10] int numPlayers, totalPoints; Public Game)://Creates game with no points or players int addPlayer(string newName) liSets up the next player in the game. Assumes no more than 10 will be made. Returns playerNum. int getNumPlayersO freturn numPlayers, lplayerNum or 0 will act like players[0] scored. Retuns that player's total score. int playerScored(int playerNum, int points) Game.Game) numPlayers totalPoints 0;) Define the addPlayer function, which takes a name and puts them into the game with 0 points. Make sure all class member variables are updated to reflect the addition of your player. Define the playe scored tunction t takes e sconng players in ex within the amay). and he num erot on s as a um ents men adds the scored points hat pla ersoalan etums ha new amountExplanation / Answer
/*Source code of the above functions are given below*/
/*NOTE: If you want to change something or want in a different way, please let me know through comments; I will surely revert back to you.*/
Question 1:
int Game::addPlayer(string newName)
{
Player p;
p.name=newName;
p.points=0;
players[numPlayers]=p;
numPlayers++;
return numPlayers;
}
Question 2:
int Game::playerScored(int playerNum,int points)
{
if(playerNum>=0 && playerNum<10)
{
players[playerNum].points+=points;
}
totalPoints+=points;
return players[playerNum].points;
}
Question 3:
int main()
{
Game match;
match.addPlayer("Alice");
match.playerScored(0,40);
return 0;
}
/*If this helps you, please let me know by giving a positive thumbs up. In case you have any queries, do let me know. I will revert back to you. Thank you!!*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.