Question
C++ implementation of a function from .h file. Directions Function: nextGeneration This function has no parameters. This function returns an int. The purpose of this
C++ implementation of a function from .h file.
Directions
Function: nextGeneration This function has no parameters. This function returns an int. The purpose of this function is to modify the grid to represent the next generation. Here's how you are supposed to do that for this assignment: Set each element of the count array to the number of live neighbors that the corresponding element in the grid array has. For each element in the grid array, set it according to the following rules: If the cell was LIVE and has less than two or more than three live neighbors, then change it to DEAD. If the cell was DEAD and has exactly three live neighbors, then change it to LIVE. Add one to the generation. Return the value of the generation instance variable.
*************************psudo-code************************
nextGeneration() {
}
*************************.h file****************************
#ifndef __AUTOMATA_H__ #define __AUTOMATA_H__ #includeusing std::ostream; class automata { private: static const char LIVE = '*'; static const char DEAD = ' '; static const int ROWS = 20; static const int COLS= 60; int generation; char grid[ROWS][COLS]; int count[ROWS][COLS]; public: automata(); void reset(); void setCell(const int r, const int col); void clearCell(const int r, const int col); bool isValidCell(const int r, const int c) const; int getLiveNeighbors(const int r, const int c) const; int getGeneration() const; int nextGeneration(); friend ostream& operator<<(ostream& strm, const automata& brd); }; #endif
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