Question: Assignment Objectives To practice declaring a two - dimensional array To practice passing a two - dimensional array as a parameter to a function To
Assignment Objectives
To practice declaring a twodimensional array
To practice passing a twodimensional array as a parameter to a function
To practice using a double for loop to store values in and retrieve values from a twodimensional array
To practice implementing a program in two increments instead of one
Assignment Summary
In this assignment you shall finish a program in C that produces a twodimensional board of bombs and numbers that could be used as a data structure inside a minesweeper game such as the one that comes with Microsoft Windows.
The display of the board shall be textbased and appear in the format shown in the exampleprogramoutput.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, and a number square shall appear as the number.
The game board data structure shall consist of a twodimensional integer array. A blank square shall be stored as a zero, a bomb shall be stored as a and a number ie clue square shall be stored as the respective number.
The program shall follow this basic algorithm:
Create a game board as a twodimensional integer array with MAXROWS and MAXCOLUMNS
Randomly fill the squares on the game board with bombs or zeros
Go through the 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 the game board on the screen
The program shall have no interaction with a user except for starting the program.
Software Design
To satisfy the software requirements, implement the design described below.
int mainvoid
This function definition is finished. Make no changes to it It contains an implementation of the basic algorithm described in the software requirements.
void fillTheGameBoardint boardMAXROWSMAXCOLUMNS
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 MAXROWS and MAXCOLUMNS constants in your 'for loop' source code instead of the literal numbers given for the those constants in the skeleton file.
Inside the innermost 'for' loop, store a BOMBDIGIT in a square when the following probability formula is true: randMAXROWS otherwise, put an EMPTYSQUAREDIGIT in the square. Be sure to use the BOMBDIGIT and EMPTYSQUAREDIGIT constants in your source code.
void displayTheGameBoardint boardMAXROWSMAXCOLUMNS
Set up a double for loop that will iterate through each row and column of the board in order to print in a width of the contents of each square as shown in the exampleprogramoutput.txt file. Inside the inner for loop, use an ifelse structure to do the following. If a square contains the BOMBDIGIT, then print the BOMBSYMBOL. If instead, a square contains the EMPTYSQUAREDIGIT then, print the EMPTYSQUARESYMBOL; otherwise, print the numeric value stored in the square.
void insertTheMineCluesint boardMAXROWSMAXCOLUMNS
This function works in conjunction with the incrementTheNeighborSquares function to put the mine number clues onto the board. To modularize the implementation, this function handles the part of finding each bomb on the board. The other function handles the part about correctly storing the number clues.
Set up a double for loop that will iterate through each row and column of the board. Do the following inside the inner for loop. If a square contains the BOMBDIGIT then call the incrementTheNeighborSquares function and pass it the board, the current row value, and the current column value.
void incrementTheNeighborSquaresint boardMAXROWSMAXCOLUMNS int bombRow, int bombColumn
The algorithm checks all of the neighbor ie adjacent squares surrounding a bomb square. If a neighbor square does not contain the BOMBDIGIT, then the value in the square is incremented by one. A double for loop is used to iterate through the row and 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 Referenced
SkeletoncppDownload Skeletoncpp
exampleprogramoutputtxtDownload exampleprogramoutputtxt
Assignment Directions
To learn more ways of coding things a skeleton has been created for you to follow. Start by downloading the source code file named skeletoncpp and the text file named exampleprogramoutput.txt
Rename the skeletoncpp file to Smithcpp where Smith is your last name and is the assignment number
Start up your IDE software and open up your Smithcpp source code file
Fill in the entries in the comment block at the top of the source code file so that they apply to this assignment
Read throug
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
