Question
(i) Suppose a C++ class is needed to represent a board game in a computer program. The class should be named Game and have one
(i) Suppose a C++ class is needed to represent a board game in a computer program. The class should be named Game and have one member variable for a 2D array of integers named game_board, with horizontal row size of BOARD_SIZE and vertical column size of BOARD_SIZE. Write a declaration for this class using the most suitable data types. Declare a default constructor and a copy constructor (with one parameter for a Game variable, passed by constant-reference). The constructors should be available outside the class but the variables should not be. (ii) Write the implementation for a function named getAt that returns the value in the array at a given position. Pass the row and column as parameters. Use the most suitable return type for the function. The function should be declared constant. (iii) Show how you would declare a variable in the main function of the Game type using the default constructor. Then show how to call the getAt function to get the value at row index of 2 and column index of 3. Save the value in a variable named pos.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started