#include <iostream>
#include <cstdlib>
using namespace std;
void setupRow();
void printRow();
void updateRow();
int findNextCellState(int left_neighbor, int cell, int right_neighbor);
const int WIDTH=80;
int row[WIDTH];
int main()
{
setupRow();
printRow();
for (int i = 0; i < 40; i++)
{
updateRow();
printRow();
}
}
// The setupRow function creates an initial state for the cellular autonoma
void setupRow()
{
int row[ WIDTH ] = {};
row[39]=1;
// IMPLEMENTATION GOES HERE
}
// The printRow function outputs the state of the row to the user. For all
// cells that are 0, it outputs a space (" "), for all cells that are 1, it
// outputs a star ("*")
void printRow()
{
if ( int row=0)
{cout<< " " <<;}
else if ( int row=1)
{
cout<< "*" <<;
}// cout << " " << when x = 0
// cout << "*" << when x = 1
// IMPLEMENTATION GOES HERE
//
//
}
// The updateRow function updates the contents of the row after calculating
// the next states using the findNextCellState function
void updateRow()
{
}
// The findNextCellState function implements the Rule 30 celular autonoma rules.
// The states for this are:
//
// 111 110 101 100 011 010 001 000
// 0 0 0 1 1 1 1 0
int findNextCellState(int left_neighbor, int cell, int right_neighbor)
{
if (0 == cell)
{
if (1 == (left_neighbor + right_neighbor))
{
return 1;
}
else
{
return 0;
}
}
else
{
if (1 == left_neighbor)
{
return 0;
}
else
{
return 1;
}
}
}
Here are the instructions that we got.
* Use a global integer array of width 80 to represent the current state
* When the main starts, use a function to populate the array with all 0s, except for the middle (40th) element which should be set to 1
* Implement a method that will print the row to the screen. Whenever the state is a 0, output a space (" ") and whenever the state is a 1, output a star("*")
* Implement a method that will look at every element in the current array, determine the next state, and save it in to a new array. When the method is finished, copy all elements of the new array in to the global array.
* Run a loop in the main method which will update the state and print out the new state 40 times
I understand that this is MY homework and I am in no way expecting anybody to do it. I just need more of a technical explanation to get started.

New Topic/Question
Reply




MultiQuote




|