Question: #include #include //for setw() #include #include #include #include //for time() in srand( time(NULL) ); #include //for Sleep() using namespace std; class Mars { private: vector>

#include

#include //for setw()

#include

#include

#include

#include //for time() in srand( time(NULL) );

#include //for Sleep()

using namespace std;

class Mars

{

private:

vector> map;

int dimX, dimY;

public:

Mars()

{

init();

}

void init();

void display();

int getDimX();

int getDimY();

char getObject(int,int);

void setObject(int,int,char);

bool isEmpty(int,int);

bool isInsideMap(int,int);

};

void Mars::init()

{

char objects[] = {' ', ' ', ' ', ' ', ' ', ' ',

'X', '#', '@', '$'};

int noOfObjects = 10; /umber of objects in the objects array

dimX = 15;

dimY = 5;

//create dynamic 2D array using vector

map.resize(dimY); //create rows

for (int i = 0; i

{

map[i].resize(dimX); //resize each rows

}

//put random chars into the vector array

for (int i = 0; i

{

for (int j = 0; j

{

int objNo = rand() % noOfObjects;

map[i][j] = objects[objNo];

}

}

}

void Mars::display()

{

system("cls");

cout

cout

cout

for (int i = 0; i

{

cout

for (int j = 0; j

{

cout

}

cout

cout

for (int j = 0; j

{

cout

}

cout

}

cout

for (int j = 0; j

{

cout

}

cout

cout

for (int j = 0; j

{

int digit = (j + 1) / 10;

cout

if (digit == 0)

cout

else

cout

}

cout

cout

for (int j = 0; j

{

cout

}

cout

}

int Mars :: getDimX(){

return dimX;

}

int Mars :: getDimY(){

return dimY;

}

char Mars :: getObject(int x, int y){

return map[dimY - y][x - 1];

}

void Mars :: setObject(int x, int y,char ch){

map[dimY - y][x - 1] = ch;

}

bool Mars :: isEmpty(int x, int y){

if(map[dimY - y][x - 1] == ' ')return true;

return false;

}

bool Mars :: isInsideMap(int x, int y){

if((x>0 && x 0 && y

return false;

}

void test1()

{

Mars mars;

mars.display();

}

void test2()

{

Mars mars;

mars.display();

cout

cout

}

void test3(){

Mars mars;

mars.display();

int x,y;

char obj;

x = 1; y = 1;

obj = mars.getObject(x,y);

cout

x = 15; y=5;

obj = mars.getObject(x,y);

cout

x = 5; y = 2;

obj = mars.getObject(x,y);

cout

x = 10; y = 4;

obj = mars.getObject(x,y);

cout

}

void test4(){

Mars mars;

mars.setObject(1,1,'A');

mars.setObject(15,1,'B');

mars.setObject(15,5,'C');

mars.setObject(1,5,'D');

mars.display();

cout

cout

cout

cout

}

void test5(){

Mars mars;

mars.setObject(2, 4, 'Z');

mars.setObject(10, 3, ' ');

mars.display();

cout

if( mars.isEmpty(2,4) )

cout

else

cout

cout

cout

if( mars.isEmpty(10,3) )

cout

else

cout

cout

cout

if( mars.isInsideMap(15,5) )

cout

else

cout

cout

cout

if( mars.isInsideMap(0,0) )

cout

else

cout

cout

}

int main()

{

srand(time(NULL));

// test1();

// test2();

// test3();

// test4();

test5();

return 0;

}

how to add The class rover and control the direction of the rover to the code above

#include #include //for setw() #include #include #include #include //for time() in srand(

time(NULL) ); #include //for Sleep() using namespace std; class Mars { private:

vector> map; int dimX, dimY; public: Mars() { init(); } void init();

1.6 Alright, Mars is ready, time to create the Rover by the name of Curiosity. Add the class Rover and the test function as below: class Rover private: int x,y: char heading; public: Rover() void land (Mars& mars); void Rover::land (Mars& mars) { char possibleHeading[] = {'*',>', ',

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!