Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE COMPLETE IN C++ LANGUAGE Location row : int = -1 col : int = -1 setLocation(row : int, col : int) getRow(): int getColl):

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
PLEASE COMPLETE IN C++ LANGUAGE
Location row : int = -1 col : int = -1 setLocation(row : int, col : int) getRow(): int getColl): int isEmpty(): bool Details Write all the code necessary to implement the Location class as shown in the UML Class Diagram to the right. Do this in a project named snake (we'll continue adding files to this project as the term progresses). Your class definition and implementation should be in separate files. When complete, you should have the following files in your project: location.h - class definition (this is provided below) location.cpp - class implementation (this you need to write) You will also need a main function to test your class, which is included at the bottom of this assignment. This can either be placed in a separate cpp file or at the end of your location.cpp file. Data details are as follows: row An int representing a row on the board" for the snake game. Row 0 will be the top row. An initial row value of -1 will be used to indicate that the row value is currently "empty or unused. An int representing a column on the for the snake game. Column 0 will be the leftmost column. An initial column value of -1 will be used to indicate that the column value is currently "empty" or unused. Function details are as follows: Location() Initialize row to - 1 (constructor) Initialize col to - 1 getRow() getColo return copies of requested data setLocation(int row, int col) Changes the row and col value of the Location to the values specified as function parameters isEmpty Returns true if the (row, col) of the Location is (-1,-1). Otherwise, returns false. No screen output (cout statements) should be generated inside the class! In the process of creating a class, you should always create test code to verify it's bug free and robust. That way, in the future, when we incorporate this into a larger program (the snake game), we won't have to debug it when we're debugging the code of the larger program. Testing each portion of a larger program individually is referred to as unit testing and is the easiest and fastest way to a complete program. Thorough testing now will save you time later!!!! Here is some recommended test code to get you started. Recommended process to complete assignment. 1. Create a new C++ project called snake with location.h and location.cpp files (put the .h into Header Files" and the .cpp into the "Source Files") 2. Copy the code below and paste into location.h. You can modify comments and other documentation, but DO NOT modify any of the code provided below. 3. Copy the list of functions into location.cpp and edit each, adding just the class name and enough code to make each into a stub function (a stub is simply an empty function, consisting of only a return statement). You'll also need to add #include "location.h" at the top of location.cpp. 4. Compile all of that to make sure it's free of syntax errors. 5. Add a main() function (either at the bottom of location.cpp or in a separate file) to test your class. You can comment out certain parts of my test code, if needed, to test the individual methods as you progress. 6. Implement each function one at a time, starting with the constructor. Test each function thoroughly before moving on to the next. Declaration of the Location class. This class is used to designate a location on a 2-dimensional board. It will be leveraged in the creation of a Snake game. #pragma once class Location public: Constructor Function Initializes the location to (-1, -1), which is an invalid board location We will interpret any location with this value as being "empty" @param none @return none Location(); Mutator Function that allows a location to be set to a specified row/col value @param int (row), int (col) @return none */ void setLocation (int row, int col); Accessor function that gets the row value for a location for a location @param @return none int (the row) int getRow(); Accessor function that gets the col value for a location @param none @return int (the column) */ int getCol(); /* Performs a query to see if the location is empty (-1, -1) @param none @return bool (true if empty, false otherwise) bool is Empty(); private: int row; // note: row 0 is the top row on the board int col; // note: col 0 is the left-most column on the board Very Important Stuff All programs should follow the class's coding conventions. Submit the following files: location.h location.cpp your executable (.exe) Your main.cpp if you chose to place the test code in a separate file

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 Databases questions