Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS IS MY PART 1 I NEED HELP WITH PART 2 #include #include #include using namespace std; const int MAX_ROW = 30; const int MAX_COL

THIS IS MY PART 1 I NEED HELP WITH PART 2

#include

#include

#include

using namespace std;

const int MAX_ROW = 30;

const int MAX_COL = 60;

//you can declare below two array even in main function

//just cut paste below two line if you don't want them to global

int currentArray[MAX_ROW][MAX_COL];

int tempArray[MAX_ROW][MAX_COL];

void displayMenu() {

cout << "[P]lay - Press 'P' to play. ";

cout << "[Q]uit - Press 'Q' to exit. ";

}

void setZeroArray(int array[MAX_ROW][MAX_COL]) {

for (int i = 0; i < MAX_ROW; ++i) {

for (int j = 0; j < MAX_COL; ++j) {

array[i][j] = 0;

}

}

}

void setInitialPatternArray(int array[MAX_ROW][MAX_COL]) {

srand(time(NULL));

int random_row = rand() % (MAX_ROW - 6);

int random_col = rand() % (MAX_COL - 6);

for (int i = 0; i < 6; ++i) {

array[random_row + i][random_col] = 1;

array[random_row + i][random_col + 6] = 1;

array[random_row + 6][random_col + i] = 1;

}

}

void copyArray(int array1[MAX_ROW][MAX_COL], int array2[MAX_ROW][MAX_COL]) {

for (int i = 0; i < MAX_ROW; ++i) {

for (int j = 0; j < MAX_COL; ++j) {

array2[i][j] = array1[i][j];

}

}

}

void displayArray(int array[MAX_ROW][MAX_COL]) {

for (int i = 0; i < MAX_ROW; ++i) {

for (int j = 0; j < MAX_COL; ++j) {

cout << array[i][j];

}

cout << endl; //newline after completion of each row printing

}

}

int main() {

char choice = 'P';

while (choice == 'P' || choice == 'p') {

displayMenu();

setZeroArray(tempArray);

setInitialPatternArray(tempArray);

copyArray(tempArray, currentArray);

displayArray(currentArray);

cin >> choice;

}

return 0;

}

***************************************************************************************************************************************

PART 2

ADD PART 1 TO PART 2!!!!

You will add the followings to the Gol_Project-Part1_yourLastName.cpp file.

1. Use the global variables properly:

const int MAX_ROW = 30;

const int MAX_COL = 60;

for example:

int currentArray[MAX_ROW][MAX_COL];

instead of int currentArray[30][60];

****In your program, replace '60' with MAX_COL and replace '30' with MAX_ROW.

2. Write the definition of the function setNextGenArray that creates a pattern of next generation (tempArray) based on the current generation (currentArray); modify the tempArray based on thecurrentArray by applying the rules of Game of Life.

Conway's Game of Life Rules:

- The neighbors of a given cell are the cells that touch it vertically, horizontally, or diagonally. - Any live cell with fewer than two live neighbours dies, as if caused by underpopulation. - Any live cell with two or three live neighbours lives on to the next generation. - Any live cell with more than three live neighbours dies, as if by overpopulation. - Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

3. Create a loop to generate and next pattern automatically.

When executing your program, the following should happen: a. Print the menu using the displayMenu function. b. Initialize the tempArray using the setZeroArray function. c. Set the U pattern in the tempArray using the setInitialPatternArray function. d. Copy the tempArray to the currentArray using the copyArray function. e. Print the currentArray using the displayArray function. f. When the user presses P, (loop the following three steps) i. Generate a next pattern using the setNextGenArray function ii. Copy the tempArray to the currentArray using the copyArray function. iii. Print the currentArray using the displayArray function. g. When the user presses Q, it will terminate the program.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions