Create a C++ program that produces a two-dimensional board of bombs & numbers that could be used as a data structure inside a minesweeper game such as the one that comes with Microsoft Windows. Display of the board will be text-based & appear in the format shown in the example-program-output.txt file with each digit or character printed in a field width of three. A blank square shall appear as an underscore character, a bomb square shall appear as a '#' character, & a number square shall appear as the number. The game board data structure shall consist of a two-dimensional integer array. A blank square shall be stored as a zero, a bomb shall be stored as a -1, & a number (i.e., clue) square shall be stored as the respective number. Program shall follow this basic algorithm: Create a game board as a two-dimensional integer array with MAX_ROWS and MAX_COLUMNS Randomly fill squares on the game board with bombs or zeros Go through board, square by square, looking for each bomb. When one is found, increment (by one) the values in the number squares surrounding a bomb Display game board on screen Program shall have no interaction with users except for starting the program. Implement the design described below: int main(void) void fillTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS]) Set up a double for loop that will iterate through each row and column of the board in order to fill the squares. Be sure to use the MAX_ROWS and MAX_COLUMNS constants in the 'for loop' source code instead of  literal numbers given for the those constants in the skeleton file. Inside the innermost 'for' loop, store a BOMB_DIGIT in a square when the following probability formula is true: (rand() % (MAX_ROWS - 3) == 0), otherwise, put an EMPTY_SQUARE_DIGIT in the square. Use BOMB_DIGIT and EMPTY_SQUARE_DIGIT constants in your source code. void displayTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS]) Set up a double for loop that will iterate through each row & column of the board in order to print (in width of 3) the contents of each square as shown in example-program-output.txt file. Inside inner for loop, use an if-else structure to do the following. If a square contains the BOMB_DIGIT, then print the BOMB_SYMBOL. If, instead, a square contains EMPTY_SQUARE_DIGIT then, print  EMPTY_SQUARE_SYMBOL; otherwise, print numeric value stored in the square. void insertTheMineClues(int board[MAX_ROWS][MAX_COLUMNS]) Set up a double for loop that will iterate through each row and column of board. Do following inside inner for loop. If a square contains the BOMB_DIGIT then call the incrementTheNeighborSquares function and pass it the board, the current row value, & the current column value. void incrementTheNeighborSquares(int board[MAX_ROWS][MAX_COLUMNS], int bombRow, int bombColumn) The algorithm checks all of neighbor (i.e., adjacent) squares surrounding a bomb square. If neighbor square does not contain BOMB_DIGIT, then value in the square is incremented by one. A double for loop is used to iterate through the row & column location of each neighbor square surrounding the bomb square. Because C++ does no range checking when an array is indexed, the algorithm checks that, also. This function definition is already finished. Make no changes to it. Files used: example-program-output Skeleton15.cpp (copied below) #include #include #include using namespace std; const int MAX_ROWS = 10; const int MAX_COLUMNS = 10; const int EMPTY_SQUARE_DIGIT = 0; const char EMPTY_SQUARE_SYMBOL = '_';  const int BOMB_DIGIT = -1; const char BOMB_SYMBOL = '#'; void fillTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS]); void displayTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS]); void insertTheMineClues(int board[MAX_ROWS][MAX_COLUMNS]); void incrementTheNeighborSquares(int board[MAX_ROWS][MAX_COLUMNS], int row, int column); int main(void) { int gameBoard[MAX_ROWS][MAX_COLUMNS]; srand(time(NULL)); fillTheGameBoard(gameBoard); insertTheMineClues(gameBoard); displayTheGameBoard(gameBoard); system("pause"); return 0; }  void fillTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS]) {       } void displayTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS]) {       }  void insertTheMineClues(int board[MAX_ROWS][MAX_COLUMNS]) {             }  // The function definition below is finished.  Make no changes to it. void incrementTheNeighborSquares(int board[MAX_ROWS][MAX_COLUMNS], int bombRow, int bombColumn) { for (int row = bombRow - 1; row <= bombRow + 1; row++)    {    if ( (row >= 0) && (row < MAX_ROWS) )            {          for (int column = bombColumn - 1; column <= bombColumn + 1; column++)          {          if ( (column >= 0) && (column < MAX_COLUMNS) && (board[row][column] != BOMB_DIGIT) )                   board[row][column]++;                      }            }       }  }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Create a C++ program that produces a two-dimensional board of bombs & numbers that could be used as a data structure inside a minesweeper game such as the one that comes with Microsoft Windows.

Display of the board will be text-based & appear in the format shown in the example-program-output.txt file with each digit or character printed in a field width of three. A blank square shall appear as an underscore character, a bomb square shall appear as a '#' character, & a number square shall appear as the number.

The game board data structure shall consist of a two-dimensional integer array. A blank square shall be stored as a zero, a bomb shall be stored as a -1, & a number (i.e., clue) square shall be stored as the respective number.

Program shall follow this basic algorithm:

Create a game board as a two-dimensional integer array with MAX_ROWS and MAX_COLUMNS

Randomly fill squares on the game board with bombs or zeros

Go through board, square by square, looking for each bomb. When one is found, increment (by one) the values in the number squares surrounding a bomb

Display game board on screen

Program shall have no interaction with users except for starting the program.

Implement the design described below:

int main(void)

void fillTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS])

Set up a double for loop that will iterate through each row and column of the board in order to fill the squares. Be sure to use the MAX_ROWS and MAX_COLUMNS constants in the 'for loop' source code instead of  literal numbers given for the those constants in the skeleton file.
Inside the innermost 'for' loop, store a BOMB_DIGIT in a square when the following probability formula is true: (rand() % (MAX_ROWS - 3) == 0), otherwise, put an EMPTY_SQUARE_DIGIT in the square. Use BOMB_DIGIT and EMPTY_SQUARE_DIGIT constants in your source code.

void displayTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS])

Set up a double for loop that will iterate through each row & column of the board in order to print (in width of 3) the contents of each square as shown in example-program-output.txt file. Inside inner for loop, use an if-else structure to do the following. If a square contains the BOMB_DIGIT, then print the BOMB_SYMBOL. If, instead, a square contains EMPTY_SQUARE_DIGIT then, print  EMPTY_SQUARE_SYMBOL; otherwise, print numeric value stored in the square.

void insertTheMineClues(int board[MAX_ROWS][MAX_COLUMNS])

Set up a double for loop that will iterate through each row and column of board. Do following inside inner for loop. If a square contains the BOMB_DIGIT then call the incrementTheNeighborSquares function and pass it the board, the current row value, & the current column value.

void incrementTheNeighborSquares(int board[MAX_ROWS][MAX_COLUMNS], int bombRow, int bombColumn)

The algorithm checks all of neighbor (i.e., adjacent) squares surrounding a bomb square. If neighbor square does not contain BOMB_DIGIT, then value in the square is incremented by one. A double for loop is used to iterate through the row & column location of each neighbor square surrounding the bomb square. Because C++ does no range checking when an array is indexed, the algorithm checks that, also.
This function definition is already finished. Make no changes to it.

Files used:

example-program-output

Skeleton15.cpp (copied below)

#include <iostream>
#include <iomanip>
#include <time.h>

using namespace std;

const int MAX_ROWS = 10;
const int MAX_COLUMNS = 10;
const int EMPTY_SQUARE_DIGIT = 0;
const char EMPTY_SQUARE_SYMBOL = '_'; 
const int BOMB_DIGIT = -1;
const char BOMB_SYMBOL = '#';

void fillTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS]);
void displayTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS]);
void insertTheMineClues(int board[MAX_ROWS][MAX_COLUMNS]);
void incrementTheNeighborSquares(int board[MAX_ROWS][MAX_COLUMNS], int row, int column);

int main(void)
{
int gameBoard[MAX_ROWS][MAX_COLUMNS];

srand(time(NULL));

fillTheGameBoard(gameBoard);

insertTheMineClues(gameBoard);

displayTheGameBoard(gameBoard);

system("pause");

return 0;

void fillTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS])
{

     
} void displayTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS])
{

     


void insertTheMineClues(int board[MAX_ROWS][MAX_COLUMNS])
{
     
     


// The function definition below is finished.  Make no changes to it.
void incrementTheNeighborSquares(int board[MAX_ROWS][MAX_COLUMNS], int bombRow, int bombColumn)
{
for (int row = bombRow - 1; row <= bombRow + 1; row++)
   {
   if ( (row >= 0) && (row < MAX_ROWS) )     
      {   
      for (int column = bombColumn - 1; column <= bombColumn + 1; column++)
         {
         if ( (column >= 0) && (column < MAX_COLUMNS) && (board[row][column] != BOMB_DIGIT) )      
            board[row][column]++;            
         }     
      }   
   } 

1 3
1
1 1 1 1 2 2 1
1 # # 3
# 3
2
# 2 1
1 1
2
1 2 # 2 # 1
2 1
# # 1
3 3 4 2 3 1 2 1 1
2 1
2 # # 2
I
#
-
2 1 1
-
4 # 2
I
I
- 1
-
-
-
I
2
1
-
-
I
-
# 2
3 #
1 2 2
# 2
1 #
1 1
Transcribed Image Text:1 3 1 1 1 1 1 2 2 1 1 # # 3 # 3 2 # 2 1 1 1 2 1 2 # 2 # 1 2 1 # # 1 3 3 4 2 3 1 2 1 1 2 1 2 # # 2 I # - 2 1 1 - 4 # 2 I I - 1 - - - I 2 1 - - I - # 2 3 # 1 2 2 # 2 1 # 1 1
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education