No HANDWRITINGS PLEASE! Design a program that will allow a user to keep track of
ID: 3749014 • Letter: N
Question
No HANDWRITINGS PLEASE!
Design a program that will allow a user to keep track of the status of a soccer game. You will design a SoccerGame class that will represent the state of the soccer game.
Its attributes are:
The name of the first team
The name of the second team
The score of the first team
The score of the second team
The status of the game (finished or in progress)
The constructor will pass in two team names and will create a SoccerGame object where the score of each team is 0 and the status of the game is in progress.
The methods for the SoccerGame class are:
Record a goal scored (add one to the team score)
Change status of the game as finished
Return the score of a team
Return the name of the team that is currently winning or has won the game
You will design a test class that allows the user to instantiate a SoccerGame object for a current game.
The user will enter the names of two teams and the program will start a soccerGame object. Then the program will allow the user to update the object as needed until the game ends.
The program will loop and allow the score to be updated each time a team scores a goal until the game has finished. At that time, the user will get the score of each team and then get the name of the team that has won the game.
The program will also change the status of the game to finished.
Test Cases:
Provide two test cases, presenting the inputs and required outputs for each case, and the resulting action of the program.
Program Files:
SoccerGame.java, TestSoccerGame.java
Explanation / Answer
The program snippet is as follows:
class SoccerGame { char team1[20]; char team2[20]; int score_T1; int score_T2; char gameStatus[25];
public:
SoccerGame() { cout<<" Enter the name of Team 1: "; gets(team1); cout<<" Enter the name of Team 2: "; gets(team2); score_T1=0; score_T2=0; strcpy(gameStatus,"In Progress"); }
void goalScored(); void changeStatus(); void returnScores(); void winningTeam(); };
void SoccerGame::goalScored() { int a; cout<<" Goal scored by which team? (1or2) : "; cin>>a; if(a==1) { score_T1++; } else{ score_T2++;} }
void SoccerGame::changeStatus() { if(strcmp(gameStatus,"In Progress")) { strcpy(gameStatus,"Finished"); } else { strcpy(gameStatus,"In Progress"); } }
void SoccerGame::returnScores() { puts(team1); cout<<" : "<<score_T1<<" "; puts(team2); cout<<" : "<<score_T2; }
void SoccerGame::winningTeam() { if(score_T1>score_T2) { puts(team1); } else { puts(team2); } }
void main() { SoccerGame S1; int ans=1; int a; while(ans==1) { cout<<" Choose any one :" <<" 1. Goal scored " <<" 2. Change status" <<" 3. Winning team" <<" 4. Return Scores"; switch(a) { case 1: S1.goalScored(); break; case 2: S1.changeStatus(); break; case 3: S1.winningTeam(); break; case 4: S1.returnScores(); break; default: cout<<" WRONG CHOICE!!"; }
cout<<" Keep Continuing?(1=yes,0=no)"; cin>>ans; }
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.