Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that: Prompts the user to enter the number of cells C. Declares

ID: 3939235 • Letter: W

Question

Write a program that:

Prompts the user to enter the number of cells C.
Declares an integer array cell[] with C elements.
Prompts the user to enter the number of time steps N.
Prompts the user to enter the list of indices of cells that contain 1

(enter negative index to nish).
Print a “ruler” line with C digits, 0 through 9, repeated

(see sample output below for clari cation).
Run the cellular automaton for N time steps, using the rules de ned above. On each time step, display the cells on one line,

printing a ‘#’ if the cell contains a 1, or a space if the cell contains a 0.

Your program's output should match the sample runs

public static void main(String[] args){

}

The data[] array contains data.length cells, with each cell containing either 1 or 0. displayCells() prints each cell of the data[] array on the same line, displaying a ‘#’ if the cell contains a 1, a space if the cell contains a 0.

The data[] array contains data.length cells, either 1 or 0. updateCells() updates each cell in the data[] array, according to the rules de ned earlier in this handout, for one step. (Hint: you will need to create a temporary array in updateCells(), make the updates into the temporary array, and copy the temporary array to the data[] array before the method returns.)

Explanation / Answer

#include 002 #include 003 using namespace std; 004 005 void setupRow(); 006 void printRow(); 007 void updateRow(); 008 int findNextCellState(int left_neighbor, int cell, int right_neighbor); 009 010 const int WIDTH = 80; 011 int row[WIDTH]; 012 int i = 0; 013 int temp[WIDTH]; 014 015 int main() 016 { 017     setupRow(); 018     printRow(); 019 020     for (int i = 0; i < 100; i++) 021     { 022         updateRow(); 023         printRow(); 024     } 025 026     return 0; 027 } 028 029 // The setupRow function creates an initial state for the cellular autonoma 030 void setupRow() 031 { 032     for(i = 0; i < 80; ++i) 033     { 034         if(i != 39) 035             row[i] = 0; 036 037         if(i == 39) 038             row[i] = 1; 039     } 040 } 041 042 // The printRow function outputs the state of the row to the user. For all 043 // cells that are 0, it outputs a space (" "), for all cells that are 1, it 044 // outputs a star ("*") 045 void printRow() 046 { 047     for(i = 0; i < 80; ++i) 048     { 049         if(row[i] == 0) 050         { 051             cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote