\$30.00

Category:

## Description

Assignment 2

Remember (ROCkET programming methodology!)

Build two grids which are each X wide and Y long where X and Y are user inputs to determine the size of the grids. Fill each cell of both grids with a ‘0’. Randomly fill 1/3 of the grid’s cells with a ‘1’. You must randomly fill each of the two grids separately so they do not have the all of the same squared filled with a ‘1’. Compare the two grids (square by square comparison) to find squares which have a ‘1’ in both grids. Create a third grid which contains a ‘1’ in squares where both of the compared grids contain a ‘1’ and has a ‘0’ in any other square.

Example in a 2 by 2 grid:

Column1 (Y) Column2

Row1 ( X)

Row2

 0 0 1 1
 1 0 1 0

Grid 1 Grid 2

 0 0 1 0

Grid 3 (Result)

For this assignment, you will need to create two grids using the Vector STL (Standard Template Library) and the appropriate functions to perform the above operations. Some basic level of error checking is also required for full credit.

Additionally, you will need to submit readable debugger screen shot(s) zoomed in on the debugging window to show the values of both grids when the user enters a 2 by 2 grid size.

Random Numbers

Example program. Remember that you only seed the random function once during an execution!

#include <iostream>
#include <cstdlib> // srand, rand
#include <ctime> // time
using namespace std;

int main ()
{
int randNum;
/* initialize random seed only once in an execution */
srand (time(nullptr));

for (int i = 0;i < 5; i++)
{
/* generate a number between 1 and 10: */
randNum = ( (int)rand() % 10) + 1;
cout
<< randNum << endl;
}
return 0;
}