Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

// Program described in class on 9/10/21 // Rules can be found in class video, short version here:: // For G[x][y] ... add all neighbors & self to find sum In the next generation, value at [x][y] is...

1 answer below »

Program described in class on 9/10/21
Rules can be found in class video, short version here::
For G[x][y] ... add all neighbors & self to find sum
In the next generation, value at [x][y] is
XXXXXXXXXXsum % 10 == 0 XXXXXXXXXX0
XXXXXXXXXXsum is under 50 XXXXXXXXXXadd 3 to cu
ent
XXXXXXXXXXsum between 50 & XXXXXXXXXXsubtract 3, but can't go below 0
XXXXXXXXXXsum over 150 XXXXXXXXXX1
XXXXXXXXXXAny neighbors outside space are 0's
*
Sample to illustrate rules:
A--
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
B--
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
*
this code does not work, but shows you how it should be structured
#include establish your sizes using variables or #define
so that it is easy to change;
remainder of code should look at these values
int NR = 6;
int NC = 6;
fill grid G with random values
use srand(seed); to set the sequence
use % high to restrict the range
int fillGrid( int G[][], int seed, int high )
{
}
print out the grid
void printGrid( int G[][] )
{
}
given grid, and an particular (x,y) location
compute the value of that spot in next generation
int checker( int a
[][NC],int x, int y )
{
}
int main()
{
    int A[NR][NC];
    fillGrid( A, 38, 20 );
    printf("A--\n");
    printGrid(A);
    for (i = __ ; i < __; ++i )
    {
        for (j = __; j < __; ++j )
        {
            B[i][j] = checker( A, i, j );
        }
    }
    printGrid(B);
    return 0;
}
Answered 2 days After Sep 17, 2021

Solution

Arun Shankar answered on Sep 19 2021
149 Votes
#include #include #include using namespace std;
#define ROWS 3
#define COLS 4
fill grid G with random values
use srand(seed); to set the sequence
use % high to restrict the range
void fillGrid(int G[][COLS], int seed, int high)
{
srand(seed);
for(int i = 0; i < ROWS; i++)
for(int j = 0; j < COLS; j++)
G[i][j] = rand() % high;
}
print out the grid
void printGrid(int G[][COLS])
{
for(int i = 0; i < ROWS; i++)
{
for(int j =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here