Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Whats wrong with my code? C++ please answer before 12:00am #include using namespace std; #include // needed for functions that start with mem #include //

Whats wrong with my code? C++ please answer before 12:00am

#include

using namespace std;

#include // needed for functions that start with mem

#include // needed for system used in program below

#include // needed for time/clock functions

int main ()

{

const long MaxCols (60);

const long MaxRows (60);

const time_t WaitTime (3);

bool Board [MaxRows] [MaxCols];

long CurrCol;

long CurrRow;

long Generation;

time_t StopTime; // time_t means unsigned 64 bit unsigned whole number

memset (Board, false, MaxRows * MaxCols * sizeof (bool)); // only guaranteed to work when setting to 0

// Allow user to initialize board as to which cells are alive or dead

for (CurrRow = 0; CurrRow < MaxRows; CurrRow++)

Board [CurrRow] [CurrRow] = true;

for (Generation = 0; ; Generation++)

{

// Show the board

system ("cls");

cout << "\tGeneration: " << Generation << endl;

for (CurrRow = 0; CurrRow < MaxRows; CurrRow++)

{

for (CurrCol = 0; CurrCol < MaxCols; CurrCol++)

cout << (Board [CurrRow] [CurrCol] ? '*' : ' ');

cout << endl;

}

// for each cell on the board

// count how many neighbors are alive

// apply rules to determine what happens to cell in next generation

// update the board

// ask if user wants to exit or not

StopTime = time (0) + WaitTime; // time (0) gets current time in seconds from Jan 1, 1970

do {

} while (StopTime > time (0)); // keep looking at clock until it is the stop time

}

}

Write a program to implement the simulation of life as described in Scientific American by Martin Gardner. The program will be implemented on a two dimensional surface of size 60 by 60 visible elements. The rules of the simulation are as follows: 1) Aninitialsetofcellsaremarkedasalivebytheuser.Thisisgeneration0.Your program will ask the user to input a set of row and column values to let the user determine which cells are alive. Display this generation. 2) Cells change for each succeeding generation by the following rules: A living cell dies of overcrowding in the next generation if it currently has 4 or more living neighbors. A living cell dies of loneliness in the next generation if it currently has only 0 or 1 living neighbors. An empty cell becomes a birth cell (becomes alive) in the next generation if it has exactly 3 living neighbors. All other cells remain unchanged. 3) The new generation becomes the current generation and is displayed. 4) Afterdisplayingeachnewgeneration,asktheuseriftheywishtocontinuetothe next generation or stop at this point.

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

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

More Books

Students also viewed these Databases questions