Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include #include #include #include / / Function to read the initial state from the input file std::vector > readInitialState ( const std::string& inputFile )
#include
#include
#include
#include
#include
Function to read the initial state from the input file
std::vector readInitialStateconst std::string& inputFile
std::ifstream fileinputFile;
if file.isopen
std::cerr "Error opening input file
;
exitEXITFAILURE;
int width, height, rounds;
file width height rounds;
std::vector boardheight std::vectorwidth false;
for int i ; i height; i
for int j ; j width; j
int cellState;
file cellState;
boardijcellState ;
file.close;
return board;
Function to print the board
void printBoardconst std::vector& board
for const auto& row : board
for bool cell : row
std::cout cell o : ;
std::cout std::endl;
Function to simulate one round of Conway's Game of Life
void simulateLifestd::vector& board
TODO: Implement the rules for Conway's Game of Life
Update the board according to the rules
int mainint argc, char argv
if argc
std::cerr "Usage: argv
;
return EXITFAILURE;
const std::string inputFile argv;
const std::string outputFile argv;
std::vector board readInitialStateinputFile;
int rounds;
std::ifstream inputFileStreaminputFile;
inputFileStream std::ws std::ws std::ws rounds; Skip the first three values
for int round ; round rounds; round
Uncomment the line below if you want to see the board after each round with a delay
printBoardboard; std::thisthread::sleepforstd::chrono::milliseconds;
simulateLifeboard;
Print the final state to the output file
std::ofstream outputFileStreamoutputFile;
for const auto& row : board
for bool cell : row
outputFileStream cell o : ;
outputFileStream std::endl;
return ;
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