Question: Details Apple Write all the code necessary to implement the Apple class as shown in the UML Class Diagram to the right. Do this in

 Details Apple Write all the code necessary to implement the Appleclass as shown in the UML Class Diagram to the right. Do

this in your project named snake (we'll continue adding files to this

project as the term progresses). apple Location : Location getApple Location() :

Details Apple Write all the code necessary to implement the Apple class as shown in the UML Class Diagram to the right. Do this in your project named snake (we'll continue adding files to this project as the term progresses). apple Location : Location getApple Location() : Location Your class definition and implementation should be in separate files. When complete, you should have the following files in your project: location.h location.cpp appleh apple.cpp You will also need a main function to test your class. This can either be placed in a separate cpp file or at the end of your apple.cpp file. You will need to comment out your main function from last week's assignment since each project can only have one main function. 17 Data details are as follows: const int BOARD_SIZE This global constant will be used for both the board height and width throughout our game. It should be declared above your class (not a private member variable) so that it will be visible everywhere in the program. appleLocation A Location representing where the apple is located on the future board for our Snake game. A location of (0,0) would correlate to the top left corner of the board. The appleLocation should either be set to the row/col values passed into the constructor or randomized between 0 and (BOARD_SIZE - 1) if no arguments are passed to the constructor. Function details are as follows: Apple(int row = -1, int col = -1) (constructor) If values are specified for row/col when the constructor is invoked, set the Apple's location to those row/col values. If the constructor is invoked without any arguments (ie the default values of -1 are used for row/col), generate a random Location for the apple that is within the constraints of the board size. Hint: A random row or column value that is valid (between 0 and BOARD SIZE-1) can be generated using the following code after including and : static bool first Time = true; if (first Time) { srand(static_cast unsigned int>(time(NULL))); first Time = false; int random = rand() % BOARD_SIZE; GetAppleLocation() Accessor function that retums the Location of the apple No screen output (cout statements) should be generated inside the class! Thorough testing now will save you time later!!!! Below is some recommended test code to get you started. Recommended test code: int maino { std::cout BOARD_SIZE - 1) std::cout BOARD_SIZE - 1) std::coutrow = row; this->col = col; Qint Location::getRow() return row; Qint Location::getCol() return col; bool Location::isEmpty() return col == -1 && row == -1; #pragma once class Location public: Location(); void setLocation(int row, int col); int getRow(); int getCol(); bool isEmpty(); private: int row; int col

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!