Arrays - One+ Multi Dimensional: Introduction To Programming CSE141 (3+1) Lab Dated: 23 Dec 2010
Arrays - One+ Multi Dimensional: Introduction To Programming CSE141 (3+1) Lab Dated: 23 Dec 2010
Objective
This lab provides understanding of one dimensional , two dimensional and n dimensional arrays
Practice Questions:
1) Return a version of the given array where all the 10's have been removed. Replace the
10’s with zeros
2) Return a version of the given array where each zero value in the array is replaced by
the largest odd value to the right of the zero in the array. If there is no odd value to
the right of the zero, leave the zero as a zero.
Example:
zeroMax({0, 5, 0, 3}) → {5, 5, 3, 3}
zeroMax({0, 4, 0, 3}) → {3, 4, 3, 3}
zeroMax({0, 1, 0}) → {1, 1, 0}
Arrays may have more than one dimension, for such things as:
// Implementing Minesweeper
Minesweeper
This is a one player game of a simplified version of the popular computer game minesweeper. First,
the user is asked if he or she wants to play on a 5x5 grid or 10x10 grid. You have two 2-dimensional
arrays that contain information about your grid. An entry in the array should either contain a 0 or 1.
A 1 signifies that there is a bomb in that location, and a 0 if none.
For example, given the array:
int bombList5by5[][]={
{0, 0, 1, 0, 0},
{0, 0, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 0, 0, 1, 1},
{0, 1, 1, 0, 0}};
Given the bomb list, we have 6 bombs on our list. The bombs are located in (row,col)
cells, (0,2), (2,1), (3,3), (3,4), (4,1) and (4,2).
If the user chooses a cell that contains a bomb, the game ends and all the bombs are displayed. If the
user chooses a cell that does not contain a bomb, a number appears at that location indicating the
number of neighbours that contain bombs. The game should end when all the cells that do not
contain bombs have been marked (player wins) or when the user steps on a bomb(player loses).