Reference no: EM132153455
I am having trouble setting up this C++ program. He wants us to use in and out stream to get out blinker and beacon. Below is the only provided instructions on the project.
"Overview: We need to start with the types of C++ tasks that should be included in the final project. We have true multidimensional arrays to work with now.
We will be talking about class objects in the coming days. We've also been doing file IO for several weeks and have had a lab #8 using it. So we end up with Conway's "Life" which can encompass all of these C++ tasks in one, hopefully, rewarding end of semester project.
The book does a very good job of describing the logic and implementation of the game. LIFE is so well known that a vast array of resources pertaining to it can be found on the internet.
Tasks: Since the project is in chapter 7, the book's version doesn't work with classes and it doesn't have any file IO. Let's address the file IO first. On the project download page in addition to the usual items there will be two data files containing very simple life community specifications.
The files have the following format: first item in the file is the number of rows the community requires, second item in the file is the number of columns the community requires, third item is the LIFE community which is stored as ‘.' (dead) or ‘O' (alive) characters in the array shape specified by the preceding two values. Here is an example of a configuration know as a still life block which can be found on the Wikipedia page:
4
4
....
.OO.
.OO.
....
In order for your project to work with these inputs you will need to specify a two dimensional array. The book specifies a 22 by 80 array. The GTA project uses a 50 by 100 (row by col) array. So long as your array is larger than the size specified by the input, your code will work with the input.
After creating the array, the code reads in the data from the input and fills out your LIFE community array with a small twist. The book suggests filling in the grid directly with asterisks for live cells and blanks for dead cells. We will use class objects instead.
The normal implementation of LIFE uses two identical arrays. One stores the now generation and one is used to store the next generation. (see the book pgs 446 & 447) We will be using one array which contains LIFE cell objects made from the simplest useful class we could think of. Our class objects will contain two Boolean data items that store the cell's life condition and one function which will age the cell.
Anti-Chaos:
Your LIFE community's size should be square and an edge length is define globally as const int edge=#. Your class is named cell and contains the public boolean variables aod_d0, aod_d1 and the void function age(). Create a general function that counts the number of living neighbors of a cell and declare its type with the following declaration: int nbors_sum(cell[edge][edge], int, int, int, int);. Your LIFE community ages a day at a time so create a general function that reads cells at d0 and determines whether that cell is alive or dead (aod) at d1.
It's declaration is: void oneday(cell[edge] [edge], int, int);. The oneday function will call the nbors_sum function. The GTA version has a fair amount of code in main() including file input and the while(true) display loop.
No credit challenge extras:
If you'd like to take full advantage of your computer's capabilities, then attempt to place the initial LIFE community at the center of the community array rather than at the upper left corner.
There is a bit of additional math associated with doing this and perhaps the addition of a number of extra variables. If you can get the modification working there are additional LIFE community seeds available from your GTAs and the internet.
Deliverables:
A project report in PDF format.