Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions