Question: The input file is still the < > . you are to store the trace of the rovers' positions. To do so, add a new

The input file is still the <> . you are to store the trace of the rovers' positions. To do so, add a new private member (dynamically allocated) *trace, and 2 public member functions addToTrace() andprintTrace(), as shown below. You may add additional member variables and member functions as needed.

class Rover {

struct coordinates coord;

struct position *trace;

public:

Rover(int, int, direction); // constructor

void move(direction, int);

void addToTrace(...);

void printTrace();

...

};

You should dynamically allocate the trace in the constructor with an initial size of 20. However, you may need to re-allocate the trace when you run out of space. Each time you re-allocate, increase the size of the array by 20.

The trace should record each position by a single unit. For example, suppose the current coordinates of a rover is (5, 5, north), then an instruction of 'forward 3' would add the following 3 positions to the trace:

(5, 6)

(5, 7)

(5, 8)

If the instruction for the rover is turn (right or left), then there isno additionto the trace. That is, addition to the trace is only made for instructionsforwardandback.

At the end of the program, (after you have printed the needed results for Exercise 24), you should print out thecomplete trace of each roverto the screen. For example, for Rover r1, for the first 4 instructions (forward 10, back 5, turn_right 90, forward 5):

Trace of Rover r1:

(0, 0)

(0, 1)

(0, 2)

...

(0, 10)

(0, 9)

...

(0, 5)

(1, 5)

(2, 5)

...

Trace of Rover r2:

...

Trace of Rover r3:

...

you can create your own file <> on yourself

forward 10

back 5

right_turn 90

forward 5

back 10

left_turn 90

left_turn 90

forward 8

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 Programming Questions!