 # Overview: Now that we have gone through the trouble of discussing ...

## Question

Show transcribed text

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include "GameOfLife.h"

Game::Game(int row, int col) {
this->row = row;
this->col = col;
this->grid = new int*[row];
this->lastGrid = new int*[row];

for (int i=0; i<row; i++) {
this->grid[i] = new int[col];
this->lastGrid[i] = new int[col];
memset(grid[i], false, col*sizeof(int));
memset(lastGrid[i], false, col*sizeof(int));
}

this->pause = 0;
this->fileOutput = 0;
this->gen_number = 0;
}

void Game::setFlat(int f) {
this->flat = f;
}

void Game::set(int i, int j, int value) {
this->grid[i][j] = value;
}

void Game::initialize() {
float fraction = 0;
while (1) {
cout << "Enter an initial population density (decimal value within 0-1): " << endl;
cin >> fraction;
if (fraction >= 0 && fraction <= 1) {

int numPositions = fraction*(this->row*this->col);
int count = 0;

while (count < numPositions) {
int r = rand() % this->row;
int c = rand() % this->col;
if (this->grid[r][c] == 0) {
this->grid[r][c] = 1;
count++;
}
}

break;
} else {
cout << "Invalid configuration. It should be within 0 to 1." << endl;
}
}
}

void Game::userInputs () {
int mode = 0;
while (1) {
cout << "Please provide boundary mode." << endl;
cout << "0. Classic Mode" << endl;
cout << "1. Doughnut Mode" << endl;
cout << "2. Mirror Mode" << endl;
cout << "Enter your choice: ";
cin >> mode;
if (mode >= 0 && mode <= 2) {
break;
} else {
cout << "Wrong choice! Please provide 0, 1 or 2." << endl;
}
}
this->mode = mode;

char pause;
char fileOutput;
cout << "Do you want a brief pause between generations (y or n)? ";
cin >> pause;
if (pause == 'y' || pause == 'Y') {
this->pause = 1;
} else {
cout << "Do you want output to a file (y or n)? ";
cin >> fileOutput;
if (fileOutput == 'y' || fileOutput == 'Y') {
this->fileOutput = 1;
cout << "Please enter output file name: ";
cin >> this->fileOutputName;
} else {
this->fileOutput...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

\$45.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available Data Structures and Algorithms Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.