Question: 1 Overview This assignment focusses on inheritance and exceptions. The assignment is out of 140 marks in total. The assignment implements a soccer team and
1 Overview This assignment focusses on inheritance and exceptions. The assignment is out of 140 marks in total. The assignment implements a soccer team and the issuing of cards for offenses that the players commit during a match. The rules of the game that are used in this assignment are explained below in the discussion of the corresponding classes.
2 Classes This section discusses the various classes of the assignment that will be required to complete the tasks discussed in Section 1. 2.1 Take Note Each of these classes header files are discussed below. You are allowed to change the header files to add helper functions and other functions as specified in the tasks. However, you are NOT ALLOWED TO CHANGE THE FUNCTIONS PROVIDED IN THE UML DIAGRAMS, except for the following: Making a function virtual, if required Making a function pure virtual, if indicated in the spec Adding calls in a derived classs constructor function definition to include calls to a base classs constructor, if required Therefore, you are NOT allowed to change the return type or the parameter list (including the variables and their types) of the provided functions. You are allowed to add a scope indicator for the parameter type, e.g. when using enum. The class specifications are provided using UML diagrams. An UML diagram will contain the following:
Figure 1: Explanation of an UML diagram
The accessSpecifier is indicated in the diagrams as follows: - indicates private # indicates protected + indicates public If no return type is indicated after the colon for a function, it means that the function has no return type, e.g. constructors and destructors.
Page 2 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30 2.2 Helper Classes This section discusses the helper classes that you must implement for this assignment. 2.2.1 Card Class The Card class defines a card that is issued when a player commits an offense. The Card class is defined as follows:
In our league, the following offenses will lead to the issuing of a yellow card: Deliberately delaying the restart of play (delayingPlay) Deliberately ignoring the required distance when a corner kick, free kick or throw-in takes place (ignoreDistanceRule) Entering or re-entering the field during play, without obtaining permission from the referee (enteringField) Leaving the field during play without the permission of the referee (leavingField) Unsporting behaviour (unsportingBehaviour) Dissent by word or action, i.e. using words or action to show disagreement with referees decision (dissent) Our league introduced a new card, namely a blue card that is issued when a player throws a tantrum (throwTantrum). A red card is issued when the following offenses are committed: Serious foul play (seriousFoulPlay) Violent conduct (violentConduct) Spitting at an opponent (spittingAtOpponent) Deliberately handling the ball to prevent the opposition from scoring a goal (deliberatelyHandlingBall) Deliberately commit an offensive to prevent the opposition from scoring a goal (offenseToAvoidGoal) Using offensive language and/or gestures (offensiveLanguageOrGestures) When the same player receives a second yellow or blue card in the match (twoSimilarCardsIssued) Therefore, the enum Colour has the following values: red, yellow and blue.
Page 3 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30 Taking the above into consideration, the enum Reason has the following values: delayingPlay ignoreDistanceRule enteringField leavingField unsportingBehaviour dissent seriousFoulPlay violentConduct spittingAtOpponent deliberatelyHandlingBall offenseToAvoidGoal offensiveLanguageOrGestures abbusiveLanguageOrGestures throwTantrum twoSimilarCardsIssued
2.2.2 Offense Class The Offense class defines an offense that a soccer player can commit. Every offense has a card that has been issued for the offense (cardAwarded) and the number of times that this specific offense has been committed (numberAwarded). The Offense class is defined as follows:
Figure 2: UML diagram of Offense class
Colour and Reason that are used in the Offense class are defined as two enums in the Card class. The requestCardColour function has to use the parameter of type Reason to determine which card should be issued, i.e. either a blue, yellow or red card. A card should be issued according to the rules explained in Section 2.2.1. The following default values should be used in the constructor: yellow and delayingPlay.
Page 4 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30 2.3 Soccer Player Classes This section discusses the various soccer player classes that are used in this assignment. The class hierarchy of these classes is:
Figure 3: Hierarchy of the Soccer Player classes
2.3.1 SoccerPlayer
The SoccerPlayer class is the base class of the player hierarchy. The definition of the class is presented in Fig- ure 4.
It is an abstract class and the abstract functions are indicated in the UML diagram with italic bold font. It has two dynamically allocated arrays, namely offensesInCareer and offensesInMatch. Each of these are one-dimensional arrays. If a player commits an offense and a card is issued, it should be added to both of these arrays if it is not already in the arrays. If the specific offense has already been added to these arrays, the offenses numberAwarded variable should be incremented by one.
Page 5 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30
Figure 4: UML diagram of the SoccerPlayer class
2.4 LeagueSoccerPlayer The LeagueSoccerPlayer class is a derived class of SoccerPlayer. Figure 5 presents the UML diagram of the class. Each LeagueSoccerPlayer has a triggerLevel and an angerLevel. These two variables will influence whether or not a LeagueSoccerPlayer commits an offense. The following default values should be used: name: Unknown surname: Unknown position: Unknown angerLevel: 0 triggerLevel: 5 numberOfOffensesInCareer: 0 maxNumberOfOffensesInCareer: 100 numberOfOffensesInMatch: 0
Page 6 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30 maxNumberOfOffensesInMatch: 4 initializeOffensesInCareer initializes the offensesInCareer array, allocating memory for maxNumberOfOffensesInCareer instances of Offense. Similarly, initializeOffensesInMatch initializes the offensesInMatch array, allocating memory for maxNumberOfOffensesInMatch instances of Offense. The number of cards of a specific colour that has been issued to the player either in his career or in the match can be determined by calling the getNumberOfOffensesInCareer or the getNumberOfOffensesInMatch function respectively. addAnOffense adds an offense to both offensesInCareer and offensesInMatch if the specific Offense is not already in the arrays. If the specific Offense has already been added to these arrays, the offenses numberAwarded variable should be incremented by one, i.e. both arrays should be searched for the specific Offense and then the offenses numberAwarded variable should be incremented by one. An Offense is unique if its Colour and Reason is unique. In other words, a yellow Card with Reason unsportingBehaviour is not the same Offense as a yellow Card with Reason dissent. commitOffense receives a Reason. Depending on the LeagueSoccerPlayers mood, an offense is committed. If the LeagueSoccerPlayers mood has the value 3, it commits an enteringField offense. If the LeagueSoccerPlayers mood has the value 4, it commits a violentConduct offense. After adding the offense to the arrays using addAnOffense, you should check whether a red card should be issued or not. If a red card should be issued, a RedCardException should be thrown. Whenever the RedCardException is thrown throughout the assignment, it will be caught in main.
Figure 5: UML diagram of the LeagueSoccerPlayer class
Page 7 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30 getMood returns the mood of the player. It should return the value as follows:
Condition Mood angerLevel < ( triggerLevel 3 ) 0
angerLevel < ( triggerLevel 2 ) 1 angerLevel < triggerLevel 2 (angerLevel > triggerLevel ) && (angerLevel < (triggerLevel 2)) 3 (angerLevel > (triggerLevel 2) 4
getHappy decrements the value of angerLevel by 1, getSad increments the value of angerLevel by 1 and getVerySad increments the value of angerLevel by 2. calculateAngerLevel is just an empty function. 2.4.1 Goalkeeper The task of the goal keeper is to defend a teams goal post, i.e. to prevent the opposition from scoring a goal. The UML diagram of the class is as follows:
Figure 6: UML diagram of the Goalkeeper class
For a Goalkeeper two measures are important, namely numberOfGoalsSaved and numberOfGoalsMissed. saveGoal is called whenever the Goalkeeper saves a goal. In saveGoal two values are updated: the value of numberOfGoalsSaved is increased by 1 the angerLevel is decremented by 2, since saving a goal makes the Goalkeeper happy
Page 8 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30 Similary, in function miss two values are updated: the value of numberOfGoalsMissed is increased by 1 the angerLevel is increased by 4, since missing a goal makes the Goalkeeper upset Sometimes, when defending the goal post, the goal keeper has to storm an opponent. In stormOpponent, angerLevel is increased by 2. Furthermore, if the goal keepers mood is 4, he commits an offense with Reason seriousFoulPlay. getHappy calls the function saveGoal, getSad calls the function miss and getVerySad calls the function miss twice and then calls the function stormOpponent. commitOffense receives a Reason. Depending on the Goalkeepers mood, an offense is committed. If the Goalkeepers mood has the value 3, it commits an unsportingBehaviour offense. If the Goalkeepers mood has the value 4, it commits a throwTantrum offense. After adding the offense to the arrays using addAnOffense, you should check whether a red card should be issued or not. If a red card should be issued, a RedCardException should be thrown. calculateAngerLevel calculates the angerLevel of a Goalkeeper based on its numberOfGoalsSaved and numberOfGoalsMissed. The angerLevel is calculated as follows: Condition angerLevel ((-2*numberOfGoalsSaved) + (4*numberOfGoalsMissed) > angerLevel) (-2*numberOfGoalsSaved) + (4*numberOfGoalsMissed)
((-2*numberOfGoalsSaved) + (4*numberOfGoalsMissed) < angerLevel) 0 || ((-2*numberOfGoalsSaved) + (4*numberOfGoalsMissed) < 0) calculateAngerLevel should be called whenever numberOfGoalsMissed or numberOfGoalsSaved are changed. The following default values should be used for Goalkeeper: angerLevel: 0 triggerLevel: 2 numberOfGoalsSaved: 0 numberOfGoalsMissed: 0 position: Goalkeeper 2.4.2 Defender A defender has to keep the ball away from the goalkeeper, prevent opposing attackers from passing or receiving the ball, and block shots. The UML diagram of the Defender class is presented in Figure 7. For a Defender two measures are important, namely numberOfShotsBlocked and numberOfShotsMissed. block is called whenever the Defender blocks a shot. In block two values are updated: the value of numberOfShotsBlocked is increased by 1 the angerLevel is decremented by 2, since blocking a shot makes the Defender happy Similary, in function missBlock two values are updated: the value of numberOfShotsMissed is increased by 1 the angerLevel is increased by 3, since not blocking a shot makes the Defender upset
Page 9 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30
Figure 7: UML diagram of the Defender class
getHappy calls the function block, getSad calls the function missBlock and getVerySad calls the function missBlock twice. commitOffense receives a Reason. Depending on the Defenders mood, an offense is committed. If the Defenders mood has the value 3, it commits an ignoreDistanceRule offense. If the Defenders mood has the value 4, it commits an offenseToAvoidGoal. After adding the offense to the arrays using addAnOffense, you should check whether a red card should be issued or not. If a red card should be issued, a RedCardException should be thrown. calculateAngerLevel calculates the angerLevel of a Defender based on its numberOfShotsBlocked and numberOfShotsMissed. The angerLevel is calculated as follows: Condition angerLevel ((-2*numberOfShotsBlocked) + (3*numberOfShotsMissed) > angerLevel) (-2*numberOfShotsBlocked) + (3*numberOfShotsMissed)
((-2*numberOfShotsBlocked) + (3*numberOfShotsMissed) < angerLevel) 0 || ((-2*numberOfShotsBlocked) + (3*numberOfShotsMissed) < 0) calculateAngerLevel should be called whenever numberOfShotsBlocked or numberOfShotsMissed are changed. The following default values should be used for Defender: angerLevel: 0 triggerLevel: 3 numberOfShotsBlocked: 0 numberOfShotsMissed: 0 position: Defender
Page 10 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30 2.4.3 Midfielder A midfielder links the offense and defense, i.e. bringing the ball up to the forwards to attack and score, and preventing the ball of the opposition from reaching the defenders. Figure 8 presents the UML diagram of the Midfielder class.
Figure 8: UML diagram of the Midfielder class
For a Midfielder two measures are important, namely numberOfLinksToGoalsFor and numberOfLinksToGoalsAgainst. linkToGoalForTeam is called whenever the Midfielder links to the forwards who successfully shoots a goal. In linkToGoalForTeam two values are updated: the value of numberOfLinksToGoalsFor is increased by 1 the angerLevel is decremented by 2, since linking to forwards that results in a goal makes the Midfielder happy Similary, in function linkToGoalForOpposition two values are updated: the value of numberOfLinksToGoalsAgainst is increased by 1 the angerLevel is increased by 3, since linking to the opposition that then scores the goal, makes the Midfielder upset getHappy calls the function linkToGoalForTeam, getSad calls the function linkToGoalForOpposition and getVerySad calls the function linkToGoalForOpposition twice. commitOffense receives a Reason. Depending on the Midfielders mood, an offense is committed. If the Midfielders mood has the value 3, it commits an ignoreDistanceRule offense. If the Midfielders mood has the value 4, it commits a seriousFoulPlay offense. After adding the offense to the arrays using addAnOffense, you should check whether a red card should be issued or not. If a red card should be issued, a RedCardException should be thrown. calculateAngerLevel calculates the angerLevel of a Midfielder based on its numberOfLinksToGoalsFor and numberOfLinksToGoalsAgainst. The angerLevel is calculated as follows:
Page 11 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30 Condition angerLevel ((-2*numberOfLinksToGoalsFor) + (3*numberOfLinksToGoalsAgainst) > angerLevel) (-2*numberOfLinksToGoalsFor) + (3*numberOfLinksToGoalsAgainst)
((-2*numberOfLinksToGoalsFor) + (3*numberOfLinksToGoalsAgainst) < angerLevel) 0 || ((-2*numberOfLinksToGoalsFor) + (3*numberOfLinksToGoalsAgainst) < 0) calculateAngerLevel should be called whenever numberOfLinksToGoalsFor or numberOfLinksToGoalsAgainst are changed. The following default values should be used for Midfielder: angerLevel: 0 triggerLevel: 2 numberOfLinksToGoalsFor: 0 numberOfLinksToGoalsAgainst: 0 position: Midfielder 2.4.4 Forward A forward is an attacking soccer player whom aims to score goals for his team. Figure 9 presents the UML diagram of the Forward class.
Figure 9: UML diagram of the Forward class
For a Forward three measures are important, namely numberOfGoalsScored, numberOfGoalsMissed and numberOfGoalsBlocked.
Page 12 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30 The function score is called whenever the Forward scores a goal. In score, two values are updated: the value of numberGoalsScored is increased by 1 the angerLevel is decremented by 2, since scoring a goal makes the Forward happy In function miss, two values are updated: the value of numberOfGoalsMissed is increased by 1 the angerLevel is increased by 4, since completing missing the goal post, makes the Forward very upset Similary, the following two values are updated in function block: the value of numberOfGoalsBlocked is increased by 1 the angerLevel is increased by 1, since a possible goal that is blocked, makes the Forward upset getHappy calls the function score, getSad calls the function block and getVerySad calls the function miss. commitOffense receives a Reason. Depending on the Forwards mood, an offense is committed. If the Forwards mood has the value 3, it commits a dissent offense. If the Forwards mood has the value 4, it commits a violentConduct offense. After adding the offense to the arrays using addAnOffense, you should check whether a red card should be issued or not. If a red card should be issued, a RedCardException should be thrown. calculateAngerLevel calculates the angerLevel of a Forward based on its numberOfGoalsScored, numberOfGoalsMissed and numberOfGoalsBlocked. The angerLevel is calculated as follows: Condition angerLevel ((-2*numberOfGoalsScored) + (4*numberOfGoalsMissed) + (-2*numberOfGoalsScored) + numberOfGoalsBlocked > angerLevel) (4*numberOfGoalsMissed) + numberOfGoalsBlocked
((-2*numberOfGoalsScored) + (4*numberOfGoalsMissed) 0 + numberOfGoalsBlocked < angerLevel) || ((-2*numberOfGoalsScored) + (4*numberOfGoalsMissed) + numberOfGoalsBlocked < 0) calculateAngerLevel should be called whenever numberOfGoalsScored, numberOfGoalsBlocked or numberOfGoalsMissed are changed. The following default values should be used for Forward: angerLevel: 0 triggerLevel: 1 numberOfGoalsScored: 0 numberOfGoalsMissed: 0 numberOfGoalsBlocked: 0 position: Forward 2.4.5 CenterForward A center forward is an attacker positioned closest to the opponents goal. He has two main objectives: scoring goals through passes from team members and distracting the defense to make room for the withdrawn striker to attack and score. The UML diagram for the CenterForward class is presented in Figure 10. For a CenterForward two measures are important, namely numberOfSuccessfulDecoyMoves and numberOfUnsuccessfulDecoyMoves.
Page 13 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30
Figure 10: UML diagram of the CenterForward class
The function decoy is called whenever the CenterForward successfully distracts the oppositions defense. In decoy, two values are updated: the value of numberOfSuccessfulDecoyMoves is increased by 1 the angerLevel is decremented by 2, since successfully decoying makes CenterForward happy In function failedDecoy the following two values are updated: the value of numberOfUnsuccessfulDecoyMoves is increased by 1 the angerLevel is increased by 3, since unsuccessful decoys make the CenterForward upset getHappy calls the function decoy, getSad calls the function failedDecoy and getVerySad calls the function failedDecoy twice. commitOffense receives a Reason. Depending on the CenterForwards mood, an offense is committed. If the CenterForwards mood has the value 3, it commits a delayingPlay offense. If the CenterForwards mood has the value 4, it commits an offensiveLanguageOrGestures offense. After adding the offense to the arrays using addAnOffense, you should check whether a red card should be issued or not. If a red card should be issued, a RedCardException should be thrown. calculateAngerLevel calculates the angerLevel of a CenterForward based on its numberOfSuccessfulDecoyMoves and numberOfUnsuccessfulDecoyMoves. The angerLevel is calculated as follows: Condition angerLevel ((-2*numberOfSuccessfulDecoyMoves) + (3*numberOfUnsuccessfulDecoyMoves) (-2*numberOfSuccessfulDecoyMoves) + > angerLevel) (3*numberOfUnsuccessfulDecoyMoves) ((-2*numberOfSuccessfulDecoyMoves) + (3*numberOfUnsuccessfulDecoyMoves) 0 < angerLevel) || ((-2*numberOfSuccessfulDecoyMoves) + (3*numberOfUnsuccessfulDecoyMoves) < 0)
Page 14 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30 calculateAngerLevel should be called whenever numberOfSuccessfulDecoyMoves or numberOfUnsuccessfulDecoyMoves are changed. The following default values should be used for CenterForward: angerLevel: 0 triggerLevel: 1 numberOfSuccessfulDecoyMoves: 0 numberOfUnsuccessfulDecoyMoves: 0 position: CenterForward 2.4.6 WithdrawnStriker The withdrawn striker plays behind the center forward with its main objective to score goals. Figure 11 presents the UML diagram of the WithdrawnStriker class.
Figure 11: UML diagram of the WithdrawnStriker class For a WithdrawnStriker two measures are important, namely numberOfDecoyGoalsScored and numberOfDecoyGoalsMissed. The function score is called whenever the WithdrawnStriker successfully scores a goal. In score, two values are updated: the value of numberOfDecoyGoalsScored is increased by 1 the angerLevel is decremented by 2, since successfully scoring makes WithdrawnStriker happy In function missGoal the following two values are updated: the value of numberOfDecoyGoalsMissed is increased by 1 the angerLevel is increased by 4, since possible goals being missed upsets the WithdrawnStriker
Page 15 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30 getHappy calls the function score, getSad calls the function missGoal and getVerySad calls the function missGoal twice. commitOffense receives a Reason. Depending on the WithdrawnStrikers mood, an offense is committed. If the WithdrawnStrikers mood has the value 3, it commits a dissent offense. If the WithdrawnStrikers mood has the value 4, it commits an abbusiveLanguageOrGestures offense. After adding the offense to the arrays using addAnOffense, you should check whether a red card should be issued or not. If a red card should be issued, a RedCardException should be thrown. calculateAngerLevel calculates the angerLevel of a WithdrawnStriker based on its numberOfDecoyGoalsScored and numberOfDecoyGoalsMissed. The angerLevel is calculated as follows: Condition angerLevel ((-2*numberOfDecoyGoalsScored) + (3*numberOfDecoyGoalsMissed) > angerLevel) (-2*numberOfDecoyGoalsScored) + (3*numberOfDecoyGoalsMissed)
((-2*numberOfDecoyGoalsScored) + (3*numberOfDecoyGoalsMissed) < angerLevel) 0 || ((-2*numberOfDecoyGoalsScored) + (3*numberOfDecoyGoalsMissed) < 0) calculateAngerLevel should be called whenever numberOfDecoyGoalsScored or numberOfDecoyGoalsMissed are changed. The following default values should be used for WithdrawnStriker: angerLevel: 0 triggerLevel: 1 numberOfDecoyGoalsScored: 0 numberOfDecoyGoalsMissed: 0 position: WithdrawnStriker 2.5 Team A team consists of 11 players, of which one is the goal keeper, 4 are midfielders, 4 are defenders, one is the center forward and one is the withdrawn striker. Furthermore, each team has one captain. The UML diagram of Team is presented in Figure 12. Each Team has an array of LeagueSoccerPlayer that represents the players. initializeTeam initializes the players array. The function addPlayer adds a player to the array players. When a player is added, numberOfPlayersAdded is incremented by 1. The maximum numbers that a team can have is 11. Therefore, in numberOfPlayersAdded this condition should be checked. If 11 players have already been added, the following error should be thrown: Team is full! Take note that there is no newline character at either the beginning or the end of the exception message. The exception will be caught in the main function. The function clearTeam removes all players from the array players and resets numberOfPlayersAdded to 0. The operator [] returns the player at the requested index. If the requested index is invalid, the following exception should be thrown: Invalid index requested! Take note that there is no newline character at either the beginning or the end of the exception message. The exception will be caught in the main function.
Page 16 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30
Figure 12: UML diagram of the Team class
getHappy iterates through the players and for each player call its getHappy function. getSad iterates through the players and for each player call its getSad function. Similarly, getVerySad iterates through the players and for each player call its getVerySad function. Whenever a goal is scored, the score of the Team should be updated. However, there is no way for the LeagueSoccerPlayer to do this. Is there perhaps some other way of doing this when getScore is called? The following default values should be used for Team: score: 0 numberOfGamesWon: 0 numberOfGamesLost: 0 numberOfGamesDrawn: 0 positionOnLog: 0 numberOfPlayersAdded: 0
Page 17 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30 2.6 Captain The captain leads and motivates the team. The UML diagram of class Captain is presented in Figure 13.
Figure 13: UML diagram of the Captain class
Whenever a player is upset, the captain has to calm the player down to prevent a card being issued against the player. calmPlayerDown decrements the angryLevel of the player passed in as parameter by 2. A captain should also motivate the team players. pepTalk iterates through the players and reduces the angryLevel of each player by 1. 2.7 Match A match has two teams and the score of the match. The UML diagram of Match is presented in Figure 14.
Figure 14: UML diagram of the Match class
Page 18 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30 score is a struct with the following members: goalsForFirstTeam that is an unsigned int goalsForSecondTeam that is an unsigned int When startMatch is called, the value of started is set to true. During the game or match, when a player scores a goal, the correct teams score should be updated. When endMatch is called, the value of ended is set to true and the value of started is set to false. In addition, the result has to be updated by obtaining the scores from each Team. Based on the score, the numberOfGamesWon, numberOfGamesLost or numberOfGamesDrawn of both teams should be updated in their respective Team classes. getFirstTeamScore returns the score of the first team in players by first obtaining the teams score and then returning the value. Similarly, getSecondTeamScore returns the score of the second team in players by first obtaining the teams score and then returning the value. The following default values should be used for Match: started: false ended: false score: 0, 0 2.8 Exception Classes This section discusses the classes that are used for the card exceptions. Figure 15 presents the class hierarchy.
Figure 15: UML diagram of Exception classes hierarchy
2.8.1 CardException A CardException has a Card that has been issued for the offense, as well as the LeagueSoccerPlayer for whom the card was issued to. The default values for Card are blue and throwTantrum. The UML diagram of CardException is presented in Figure 16.
Page 19 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30
Figure 16: UML diagram of CardException class
2.8.2 RedCardException RedCardException inherits from CardException. It is used only to throw an exception when a red card is issued. Figure 17 presents the UML diagram of the class.
Figure 17: UML diagram of RedCardException class
3 Tasks
Your task is to implement all of the classes according to the specification of this assignment and the UML dia- grams.
The following tasks will be marked: 1. All constructors work correctly and the correct default values for angryLevel, triggerLevel and mood are displayed for all the players in a Team. (18 marks) 2. All constructors work correctly and the correct default values for name, surname and position are displayed for all the players in a Team. (18 marks) 3. Correct values are displayed for each team member after Teams getHappy, getSad and getVerySad functions are called in any combination or order. (36 marks) 4. Correct exceptions are thrown according to the spec. (28 marks) 5. Correct values and exceptions are obtained during a match. (40 marks)
Page 20 of 21
COS 110: Assignment 3/ Taak 3: Deadline: 2017/09/09 at 23h30 / Sperdatum: 2017/09/09 om 23h30 4 Submission Once you are satisfied that your program is working, compress all of your code, including a working Makefile, into a single archive (either .tar.gz, .tar.bz2 or .zip) and submit it for marking to the appropriate upload link (Assignment 3s various upload slots) before the deadline. Each task will have its own upload slot. However, all your code should be included in the archive for all tasks. Your Makefile should compile your code to an executable named main. The name of the Makefile should be Makefile. IMPORTANT: Remember that your Makefile must have a static flag and a run rule at the end of your makefile to execute your compiled program. That is: run : . / main Also ensure that you have NO folders or subfolders in your archive file. The following names should be used for your files: Card.h and Card.cpp Offense.h and Offense.cpp SoccerPlayer.h and SoccerPlayer.cpp LeagueSoccerPlayer.h and LeagueSoccerPlayer.cpp Goalkeeper.h and Goalkeeper.cpp Defender.h and Defender.cpp Midfielder.h and Midfielder.cpp Forward.h and Forward.cpp CenterForward.h and CenterForward.cpp WithdrawnStriker.h and WithdrawnStriker.cpp Captain.h and Captain.cpp Team.h and Team.cpp CardException.h and CardException.cpp RedCardException.h and RedCardException.cpp
Please show all .cpp files and .h files
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
