Question
In Part B, you will convert your board module to an encapsulated class. The Board class will not have a class invariant. By the end
In Part B, you will convert your board module to an encapsulated class. The Board class will not have a class invariant.
By the end of Part B, your Board class will have the following public member functions:
Board ();
void print () const;
const Tile& getAt (const CellId& cell_id) const;
void setAt (const CellId& cell_id, const Tile& value, unsigned int owner);
You will also have the following private member functions:
void printColumnNameRow () const;
void printBorderRow () const;
void printEmptyRow () const;
void printDataRow (int row) const;
Perform the following steps:
- Declare a Board class. It should have a 2D array of Tiles as a private member variable. Remove the Board typedef.
- Convert the existing function prototypes to member functions or copy in the ones shown above. Update the implementation file to match.
- Convert the boardInit function into a default constructor. When assigning values to the board array, use the non-default Tile constructor. The syntax is: array_name[i][j] = Tile(put parameters here);
- Change the getAt and setAt functions to take a const reference to a CellId as a parameter instead of a row and a column.
- Add a precondition to the getAt and setAt functions, enforced by an assert. It should require that the cell is on the board.
- Hint: You have a function to check that a cell is on the board.
- Add a parameter to the setAt function for the new tile's owner. The function should set the new tile on the board to have that owner. And a precondition that the tile parameter does not already have an owner.
- Hint: Use a function from the Tile class to change the owner.
- Test your Board class using the TestBoard3.cpp program provided.
- Update your main function to use the new Tile and Board classes. It should run as before.
- Write interface specifications for the four public functions in the Board class. Use the format described in class and in Section 4a of the online notes. You do not have to write interface specifications for the private functions.
- Reminder: Interface specifications are written for other programmers who want to use your module.
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