Lab 6

Store all of your files for this lab in a folder named "lab6".

In this lab you will create and improve on one class named Board. Board will represent an NxN grid of characters where N is specified upon an initialization of this class.

All exercises shall be done inside board.cpp

Exercise 1

Start by creating the Board class inside board.cpp. Start with this code and replace the comments with your own code to implement the member functions:

class Board { private: vector< vector<char> > data; public: explicit Board(int n) { /* Resize this->data to have size NxN and set all character elements to '.' */ } char& operator()(int row, int col) { /* Return reference to character at (row,col) */ } const char& operator()(int row, int col) const { /* Read-only version of operator(). Does same as above */ } };

Exercise 2

Add this additional member function: void clear();

and implement it so that it sets all characters in this->data to '.'

Exercise 3

Implement two additional member functions: bool operator==(const Board& other) const; bool operator!=(const Board& other) const;

which shall be used for comparing the contents of two boards. operator== returns true if the other board is equal to the current board instance, false otherwise. operator!= returns true if the other board is NOT equal to the current board instance, true otherwise.

Exercise 4

Overload the insertion operator so that you any Board instance can be displayed on an output stream.

Add this line right after class Board {: friend ostream& operator<<(ostream& os, const Board& board);

then place the following function outside the class and complete it:

ostream& operator<<(ostream& os, const Board& board) { /* Use the insertion operator on os to write a string representation of board */ return os; }