Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need help with this using C++ and all the code you need is in this link : https://drive.google.com/drive/folders/1Fvqyu5P41yHLkoDL_J8fIV0eXgg4-ED9 1. First of all, review your

i need help with this using C++ and all the code you need is in this link : https://drive.google.com/drive/folders/1Fvqyu5P41yHLkoDL_J8fIV0eXgg4-ED9

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
1. First of all, review your code and document it. a. What is the minimal documentation? Lets consider 4 aspects: Header file comments, function comments, consistent naming (for classes, variables, constants), b. For code {CPP and H files) your header files comment should have (at least): /******$*********************************** FILE: [File name] PURPOSE: [Describe in one single line] AUTHOR(S): [Your name / your team with IDs] PROFESSOR: [Your Lab Professor name] COURSE: [CST8219 LAB Your Lab number] *##*#*****************#*******##*******#**/ c. For Makefiles: ###########if############################### # FILE: [File name] # PURPOSE: [Describe in one single line] if AUTHORS): [Your name / your team with IDs] if PROFESSOR: [Your Lab Professor name] if COURSE: [C5T8219 LAB Your Lab number] imammwucwumxwwmwmwwu d. For specific functions / methods (not required for constructors, destructors, getters and setters): l****$$$$$*********$**t$**********t$$$#t********$$$#t****** * Function name: [Function Name] * Purpose: [Brief description] * Parameters: * [Var Name] = [1 line description] * Return value: [What is supposed to be returned] $$$********$$$$$$*********$**$$$************#$$#$********$*t*l e. For classes. here is the model: /***tt$$$$$$$$$$$$$$$$tt***********t$$$$$$********$$$$$$$$$$$ * Class name: [Class Name] * Purpose: [Brief description] * Properties: * [Propertyl] = [1 line description] * [PropertyZ] = [1 line description] * [...] $$$********t$$$$*********$**$t$************$$$$********$*$*t/ f. Naming: Give appropriate names for functions (when not defined in specification) and variables, that can make clear the purpose of each one. g. Any additional comments that you consider useful about the code, feel free to do it. h. TIP: See prof. Frank video. Remember that good documentation is a required skill during your professional activity, when he talks about \"living document\" and "mindmap" ideas. 2. Now, prove that you can use Git: create a branch called Lab3. a. Open git bash and navigate to your project on your hard drive. b. In git bash. type "git branch\" to see in which branch you are. c. This means that your current project is the result of applying all the commits in time. d. Type the command: \"git branch Lah3\". e. Type \"git checkout Labs\" so that git will now add commits to the Lab3 path instead. f. Make sure that you are on your week5 branch by typing: \"git branch". 3. There should be a star beside labs. 3. At this time, your class Game (composed by a CPP and a H le) contains some attributes (name. numPl'ayers and timeout) and constructors' methods. Start now doing some modifications: a. When you are passing just some parameters (for instance, the name and the timeout or, simply, the numPlayers), you need to set the others as default values. h. For instance, in your Game.h, you can find: Game::Game(string name, int nPlayers]: Game(name, nPlayers. -1) {} c. Note that with this, previous constructors (using 0, 1 or 2 parameters) can now be removed otherwise, compilation error will appear. 4. Create a new class for Player now (also from CST8219 namespace). The members (properties) are described as follows (to be defined in Player.h): class Player { private: string name: 1/ Game player name int points; // Current points bool isCurrentPlayer; // Indicates if he/she is the current player a. This class must have similar methods from Game (include default constructor): Player(string name = "[Nonamel", int points = 0, heel isCurrentPlayer = false); void printPlayer(); Player setPlayer(string, int, bool); Player(const Player& copy); Player(Player* copy]; b. Implement these methods in the Player.cpp. 5. Now modify the Game to include a list of players: a new private attribute is required: vector playersList; a. This attribute is not used in the initialization, but you need to have a new function to use it: createPlayersi) that is responsible to create this list with the specific number of players (see the property numplayers). h. Note that because players start with 0 points and they are not supposed to be the current, the only parameter asked from the user is the name. c. Now, in Game, create a new method to list the players (listPlayers()) and use the elegant iterator showed in last lab: for (Player p : playersList) p.printPlayer(|; Part II - Steps about Overloading 6. Implement the output operator: ostream& operator > ( istream&, Game &g): a. So that it asks the user to provide inputs (similar to previous function createOneGameU) that is received remember to validate the inputs. b. You should declare the output operator as a friend of the Game class and directly access the private variables of the Game class when writing them to the stream. c. TIPS: iv. In the header file. you should declare the output operator as a friend of the Game class and directly access the private variables of the Game class when writing them to the stream. v. In the implementation will require to explicit the namespace scope: CST8219::operator>> 8. Implement the assignment operator: operator=(Game 81) a. This should make the attributes (name, numplayers and timeout) equal to those of the object that are being passed in. . It is similar to a copy constructor. only now you are not initializing memory. c. Don't forget that the return type of the function should be Game& so that you can write something like: gamel = gameZ = game3 = game4; a. This makes game3 = game4, but then returns game4 so that it is used for the next assignment: gameZ : game4; b. Also, veh4 shouldn't change, so make the Game parameter to be a const object. 9. Implement the comparison operator: operator==(const Game &): a. This function should return true if all properties (name, numplayers and timeout) are both equal to the parameter's variables. 10. Implement the inequality operator: operator!=(const Game&). a. This should just return the negation of the comparison operator before described. 11. Implement the prefix and postfix increment and decrement operators: . Operator ++ () . Operator ++ (int i) . operator -- () . operator -- (int i) For a Game, you should increment or decrement the numplayers (only). b. Remember to test (when incrementing) if the numplayers is between 1 or 10. c. So, Game("Test1", 1, 1000) would be incremented to: Game("Test", 2, 1000), but the decrement of Game("Test", 1, 1000) is not possible. 12. Create a function to test these operations. Here an example (testOperators()): void testOperators() { Game original; Game copy(original); // copy constructor by reference cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions