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

I am using visual studios and need to write this in C++ In this assignment you w

ID: 3606880 • Letter: I

Question

I am using visual studios and need to write this in C++

In this assignment you will help the USS Enterprise navigate through space, by helping the captain (user) scan far-off sectors.

1) In your code, initialize a two dimensional character array with a 10x10 map of the sector in the ship’s general vicinity. Your map should consist of the following symbols:

E for Enterprise

K for Klingon Ship

R for Romulan Ship

* for Star

B for Starbase

. for empty space

There is only one Enterprise, which must be present. Please use at least 3 of the other symbols.

2) Ask the captain (user) to specify what region he is interested in by inputting a row, followed by a column.

3) Scan the sector and report what, if anything, is present there. Remember, the rows and columns must be ordered as in the diagram above.

Explanation / Answer

The required working code in C++

#include <iostream>

#include <string>

#include <cstdlib>

#include <time.h>
using namespace std;

// use enterprise (E) only once so flag for first E
bool firstE = true;

// function for generating random symbols
char getSymbol()
{
//symbols available
char symbols[6] = { 'E', 'K', 'R', '*', 'B', '.' };

//generate random number
int indx = rand() % 6;

if (indx == 0 && firstE == true)
{
    firstE = false;
    return symbols[indx];
}

return symbols[(rand() % 5) + 1];

}

int main()
{
int row, coloum;
// char array defined
char CharArray[10][10];

// seed random number generator
srand(time(NULL));

// fill the array
for (int i = 0; i < 10; i++)
{
    for (int j = 0; j < 10; j++)
    {
      CharArray[i][j] = getSymbol();
    }
}

//ask user inputs
cout << "Enter the interested region :" << endl;
cout << "Enter the row :" << endl;
cin >> row;
cout << "Enter the coloum :" << endl;
cin >> coloum;

cout << "The region near the entered location is: " << endl;

// print region near the enter location
for (int i = -1; i < 2; i++)
{
    for (int j = -1; j < 2; j++)
    {
      cout << CharArray[row + i][coloum + j] << "    ";
    }
    cout << endl;
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote