Lab 7

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

In this lab we will make a simplified version of the minesweeper game.

Exercise 1

Copy the code you have for the Board class and place it into a file named ms.cpp.

Modify ostream& operator<<(ostream& os, const Board& board) so that rows and columns are labeled like this:

0 1 2 3 4 0 . . . . . 1 . . . . . 2 . . . . . 3 . . . . . 4 . . . . .

You can use manually insert spaces to os, or you can use the setw function found in <iomanip>.

Exercise 2

Create a class named Minesweeper with Board as a public base class. This class will represent a 5x5 grid and it will contain 4 random coordinates of where mines are hidden in the grid.

Exercise 3

Implement void reveal(int row, int col) as a public member function of Minesweeper. This function will set the character at (row, col) to 'M' if there is a mine at that location, or 'C' there is no mine (C stands for clear).

After completing all three exercises:

Test your class using this main function: int main() { Minesweeper ms; int row, col; int guesses = 0; while (guesses < 21) { cout << ms << endl; cout << "Enter row and column: "; cin >> row >> col; ms.reveal(row, col); if (ms(row, col) == 'M') break; ++guesses; } cout << ms << endl; return 0; }

The game is played by having the player select coordinates. Once 21 coordinates have been selected without encountering a mine, that means the last 4 coordinates are where the mines are at and the player has won.