Question: Copy your class Robot from the previous question. Add the public functions turnLeft, turnRight moveForward . The functions should update the robot's x, y, and

Copy your class "Robot" from the previous question.

Add the public functions turnLeft, turnRight Copy your class "Robot" from the previous question. Add the publicmoveForward. The functions should update the robot's x, y, and heading attributes and should not return anything.

turnLeft and turnRight should update the robot's heading. If the robot's heading is 'N', turnLeft should result in the new heading being 'W'

moveForward should update the robot's x or y position by 1. If the robot's heading is 'N', moveForward should result in the y position increasing by one. If the robot's heading is 'S', moveForward should result in the y position decreasing by one. based on the following code:

class Robot{ public: int x; int y; char heading; int getX() { return x; } int getY() { return y; } char getHeading() { return heading; } void setX(int a) { x=a; } void setY(int b) { y=b; } void setHeading(char h) { heading=h; } Robot(int start_x, int start_y,char start_heading){ x=start_x; y=start_y; heading=start_heading; }

};

5 3 -2 01 2 3 5 3

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!