Question: Use Vectors: Multidimensional arrays. Create a project Example_MultArrays. Implement a program that keeps track of shots fired in a battleship game. Your program should ask

Use Vectors:

Multidimensional arrays. Create a project Example_MultArrays. Implement a program that keeps track of shots fired in a battleship game. Your program should ask the user if she wants to take another shot, ask for shot coordinates and then print the locations of all shots fired so far in a grid.

Here is an example dialog:

2. Another shot? [y/n] y

3. Location? a 1

4. All fired shots

5. a b c d e

6. 1 * *

7. 2 *

8. 3

9. 4 * *

10. 5 *

11. Another shot? [y/n] y

12. ...

You do not have to keep track if multiple shots were fired in the same location, i.e. you should show a single star to indicate that the shot was fired there. You should store the shots in a two-dimensional array of booleans. You should use the below as a starting point.

// Keeping track of shots fired in Battleship game

// using multidimentional arrays

// size of the ocean

//use proper headers and using statments

const int oceanLength = 5; const int oceanWidth = 5;

int main(){ bool shots[oceanLength][oceanWidth];

// place your code here }

Refer to the program below for multidimensional array example usage.

// elementary multidimensional array usage

#include

using std::cout; using std::endl;

int main ()

{

const int length=5, width=2;

int a[length][width]; // declares an integer array of 5 rows and 2 columns

// initializes the arry

for(int i=0; i < length; ++i)

for(int j=0; j < width; ++j)

a[i][j] = i*width+j;

// outputs each array element's value

for (int i=0; i < length; ++i)

for (int j=0; j < width; ++j)

cout << "a[" << i << "][" << j << "] = " << a[i][j]<< endl;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!