Question
Hello, I am a C++ Student and I am confused on how to properly set up this program to run properly. The majority of this
Hello, I am a C++ Student and I am confused on how to properly set up this program to run properly. The majority of this program is already written, but I need help in finishing it. There are two empty sections at the end of the program where code needs to be filled in, and the task of what needs to be executed is written above them. I have submitted this before but I didn't get a response from a tutor. I have condensed the program so it is easier to interpret. Any help would be much appreciated. Thank you.
Description:
This program uses the rules from Conway's Game Of Life (http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)
The game board, a size by size boolean array, is initialed to hard-coded data for the cells in the game.
The game will prompt the user for the number of cycles to run, pausing for a keystroke between each cycle.
The program can be ended anytime by pressing CTRL c.
1 represents a live cell
0 represents a dead cell
The rules are as follows:
1. Any live cell with fewer than two live neighbors dies, as if caused by underpopulation.
2. Any live cell with more than three live neighbors dies, as if by overcrowding.
3. Any live cell with two or three live neighbors lives on to the next generation.
4. Any empty cell with exactly three live neighbours becomes a live cell, as a new cell is born.
*/
#include
#include
using namespace std;
const int Bsize = 24;
typedef bool BoardType[Bsize][Bsize];
void display(BoardType Board, int Iteration);
bool WillBeAlive(BoardType Board, int Row, int Col);
void populate(BoardType Board, BoardType Board2);
// A function prototype can't be used with an inline function. (See the function NumLiveNeighbors below).
// Just be careful to use it only after the function is defined. A function is made inline for speed, as
// the overhead of the function call is eliminated. This is often used for a function that is called many times.
int main(void)
{
int Iteration = 0; // needs to be initialized here to properly count
int NumCycles;
BoardType Board2;
BoardType Board = // Here is the initial data for the board. 1 is taken to mean true and 0 to mean false.
{
0,1,0,0,1,1,0,0,1,1,0,0,0,0,1,1,0,0,1,1,0,0,1,0,
1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,1,1,0,0,1,0,1,1,1,
0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,
0,1,1,1,0,0,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,1,1,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,
1,0,1,0,1,0,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,1,1,1,
0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
0,0,1,0,1,1,1,1,1,1,0,1,0,1,1,1,1,0,0,0,0,1,1,1,
1,0,0,0,1,1,1,1,1,1,1,0,1,1,1,1,1,0,0,0,0,1,0,1,
1,0,1,0,1,0,0,0,0,0,1,0,1,1,1,1,1,1,0,1,0,1,0,1,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,
0,0,0,0,1,1,1,1,0,1,0,1,1,1,1,1,0,0,0,1,0,1,1,1,
0,1,0,1,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,0,1,0,
1,1,1,1,1,1,0,0,0,0,1,0,1,0,1,0,0,0,0,0,1,1,1,1,
1,0,0,0,0,1,0,1,0,1,0,1,1,1,0,1,0,1,0,1,0,1,1,1,
0,0,0,0,1,1,1,1,1,0,1,0,1,0,1,1,1,1,0,1,0,1,0,1,
0,1,1,1,1,0,1,0,1,0,1,0,1,0,1,1,1,1,0,1,0,1,0,1,
1,1,1,1,1,0,1,0,1,0,1,1,1,1,1,0,0,0,1,0,0,0,0,0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
0,1,1,1,0,0,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,1,
0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,0,0,1,0,1,1,1,1,0,
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,
0,1,0,0,1,1,0,0,1,1,0,0,0,0,1,1,0,0,1,1,0,0,1,0
};
cout << "Enter the number of cycles through which to run the game:" << endl;
cin >> NumCycles;
cout << "You will need to press a key such as Enter between cycles" << endl;
cout << "Press CTRL c to exit at any time." << endl;
system("PAUSE"); // Wait for the user to press a key
system("cls"); // Clear the screen.
display(Board, Iteration); // Display iteration 0
for (int Iteration = 1; Iteration <= NumCycles; Iteration++)
{
system("PAUSE"); // Creates the pause between generations
system("cls"); // Clears the screen
populate(Board, Board2);
display(Board, Iteration);
}
cout << "END OF GAME!";
system("PAUSE"); // Wait for the user to press a key
return 0;
}
/* Given:BoardA 2D array of type bool, serving as the matrix for the game
RowAn integer defining the row of the cell being checked
ColAn integer defining the column of the cell being checked
Task: Calculate the number of live neighboring cells.
Return: In the function name, return the count of the number of live neighbors.
*/
inline int NumLiveNeighbors(BoardType Board, int Row, int Col)
{
// Fill in the needed code.
}
/* Given:BoardA 2D array of type bool, serving as the matrix for the game
RowAn integer defining the row of the cell being checked
ColAn integer defining the column of the cell being checked
Task: Calculate the number of live neighboring cells using the NumLiveNeighbors function.
Determine if the cell being studied will be alive or dead in the next generation. (See rules above)
Return: True If the cell will be live in the next generation
FalseIf the cell will be dead in the next generation
*/
bool WillBeAlive(BoardType Board, int Row, int Col)
{
// Fill in the needed code.
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started