Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

  1. Declare a Board class. It should have a 2D array of Tiles as a private member variable. Remove the Board typedef.
  2. Convert the existing function prototypes to member functions or copy in the ones shown above. Update the implementation file to match.
  3. 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);
  4. Change the getAt and setAt functions to take a const reference to a CellId as a parameter instead of a row and a column.
  5. 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.
  6. 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.
  7. Test your Board class using the TestBoard3.cpp program provided.
  8. Update your main function to use the new Tile and Board classes. It should run as before.
  9. 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

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions