Game of Life Implementation in C++, Using Code::Blocks, Homework

Verified

Added on  2019/09/19

|1
|340
|181
Homework Assignment
AI Summary
This assignment involves creating a C++ program to implement Conway's Game of Life. The program utilizes a 2D array to represent the game board and includes functions for initialization, display, and pattern creation. The program initializes a 'U' pattern, allowing the user to either play the game or quit. Key functions include setZeroArray for initializing the array, setInitialPatternArray for creating the initial pattern, copyArray for copying arrays, and displayArray for printing the current state of the game. The solution provided covers all aspects of the assignment, including the program's structure, functionality, and integration within the Code::Blocks environment.
Document Page
You will be creating a simple version of Game of Life.
Write a C++ program that tests the function main and the functions discussed in steps1 through 7.
1. Declare two global variables:
const int MAX_COL = 60;
const int MAX_ROW = 30;
2. Declare 2 two-dimensional arrays of type int using the size specified in step 1.
currentArray and tempArray
3. Write the definition of the function displayMenu that displays the following menu.
[P]lay – Press 'P' to play.
[Q]uit – Press 'Q' to exit.
4. Write the definition of the function setZeroArray that initializes any two-dimensional array of type
int to 0.
5. Write the definition of the function setInitialPatternArray that creates the pattern of ‘U’ using ‘1’ in
any two-dimensional array of type int. The following shows a portion of an array. Use the
predefined rand() function to determine the row and column of the first 1 (bold).
000000000
010000010
010000010
010000010
010000010
010000010
011111110
000000000
6. Write the definition of the function copyArray that copy a two-dimensional array to another two-
dimensional array.
7. Write the definition of the function displayArray that prints any two-dimensional array of type int.
8. 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’, you will repeat a through e only once.
When the user presses ‘Q’, it will terminate the program.
Make sure that it compiles using Code::Blocks.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
[object Object]