Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Description In this project you will be writing a program simulating the Game of

ID: 3633567 • Letter: D

Question

Description
In this project you will be writing a program simulating the Game of Life.
Assumptions:
• The grid always consists of characters and has 20 rows and 40 columns
• The program should always keep track of the grid and the current iteration of evolution

All functionality must be implemented using the functions that are described to you. Hence, inside the main menu you should only use function calls and display results.
The main menu should always display the grid with the current living cells.
• Implement the function

void showGrid(const char grid[ROWS][COLUMNS])
? This function displays all cells of the grid
• Use the showGridfunction to display the grid every time you present the user with the main menu
• Display the current iteration of evolution

You will then provide the user with the following choices.
1. Load file
o Implement the function:

bool load(string filename, char grid[ROWS][COLUMNS])
This function opens the file with the given filename If the file could not be read return false. Remove all living cells from the current grid. Read all row-column pairs from the file representing the position of living cells in a grid and add them into the current grid.
Upon successfully reading in the positions return true
o Ask the user for the name of a file
o Use the load function to load the cell positions from the file
o Reset the iteration of evolution accordingly

2. Evolve
o Implement the function:

void evolve(char grid[ROWS][COLUMNS])
This function creates an integer grid of 20 rows and 40 columns called adjustmentGrid
Use the computeAdjustment function to compute the necessary adjustment for each individual position in the grid
Perform the adjustment for each of the individual positions
• If the adjustment is positive then place the character X at the position
• If the adjustment is negative then remove all characters from the position
o Use the evolve function to move the cells into the next iteration of evolution
o Increase the iteration counter

3. Exit the program
Once a particular option has been completed the grid and the main menu should be displayed again until the user selects to exit the
program. If the user enters an invalid choice, display an error message and redisplay the main menu.

Additional functions
In order to execute the simulation you will need the following additional functions:

int computeAdjustment(int row, int column, char grid[ROWS][COLUMNS])
• This function computes the adjustment that is going to be made for a specific position of the grid
? If a cell is about to grow at the position return 1
? If a cell is dying at the position return -1
? In case there is no adjustment for the position return 0
• Use the countNeighbors function to determine how many living cell neighbors the current cell has
• Then use the following mathematical rules for the Game of Life to determine what adjustments are to be made:
? Each living cell with one or no neighbors dies because of loneliness
? Each living cell with two or three neighbor survives
? Each living cell with four or more neighbors dies because of overpopulation
? Each position that does not have a living cell but has exactly three neighbors grows a living cell

int countNeighbors(int row, int column, char grid[ROWS][COLUMNS])
• This function determines how many living cells are neighbors of the specified position of the grid
• Keep in mind that every position of the grid has 8 neighbors:
column-1 column column+1
row-1 x x x
row x current position x
row+1 x x x
• Count the number of living cell neighbors and return it

Explanation / Answer

#include #include #include #include using namespace std; const int ROWS = 20; const int COLUMNS = 40; void showGrid(const char grid[ROWS][COLUMNS]); bool load(string file, char grid[ROWS][COLUMNS]); void evolve(char grid[ROWS][COLUMNS]); int countNeighbors(char neighborGrid[ROWS][COLUMNS], char grid[ROWS][COLUMNS]); int computeAdjustment(int row, int column, char grid[ROWS][COLUMNS]); int countNeighbors(int row,int column , char grid[ROWS][COLUMNS]); int main() { char malarky[20][40]; int menu = 0; while (menu < 2) { int option; int iteration = 0; string file; cout