Question: #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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
