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

Multidimensional arrays: Implement a program that keeps track of shots fired in

ID: 3534582 • Letter: M

Question

Multidimensional arrays: 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:


// Keeping track of shots fired in Battleship game
// using multidimentional arrays

// size of the ocean
const int OCEAN_LENGTH = 5;
const int OCEAN_WIDTH = 5;

int main(){
bool shots[OCEAN_LENGTH][OCEAN_WIDTH];
// place your code here
}



Refer to this program for multidimensional array example usage.


// elementary multidimensional array usage

#include <iostream>
using namespace std;


int main (void){
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;

}


Explanation / Answer

http://ideone.com/So7RYv

Dr Jack
Hire Me For All Your Tutoring Needs
Quick quotes • Clear explanations • Study support
Chat Now And Get Quote