Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Create a class CRobotMobile that Inherits from CRobot It is further characterized by the integer attributes abs and ord which define the position of

image text in transcribed

2. Create a class CRobotMobile that Inherits from CRobot It is further characterized by the integer attributes abs and ord which define the position of the RobotMobile Has a method move(...) which allows the Robot to move forward according to its orientation if it moves east from x, the abscissa (abs ) increases by x o if it moves west from x, the abscissa (abs ) decreases by x o if it moves north from x, the ordinate (ord) increases by x o if it moves south from x, the ordinate (ord) decreases by x Has a displayPosition() method that displays the position (coordinates). 5 (a) Write a constructor without arguments of the CRobotMobile class. (b) Write a four-argument constructor (type, sn, abs, ord) of the CRobotMobile class. (c) Redefine the method display() while using the parent class and the method displayPosition(). (d) Write a program that tests your CRobotMobile by performing the following actions: . i. Turn East . ii. Move West by 4 steps iii. Go North 6 steps . iv. Move 14 steps to East v. Move back 8 steps to the South Serial number : FOFO State : False The following is a sample of Run (input/output) : Orientation : 1 Type : Mobile 1 # create a dictionary for the directions of move X: 0 2 direction = { Y: 0 3 "North" : 1, Serial number : FOFO 4 "East" : 2, State : False "South" : 3, Orientation : 2 6 "West" : 4 Type : Mobile X: 0 7 } Y: 0 8 Serial number : FOFO # Create a robot State : False 10 robot = CRobotMobile() 11 robot.display() Orientation : 4 12 # Orientation to the East Type : Mobile X: 0 13 robot.setOrientation(direction[ "East"]) Y: 0 14 robot.display ( ) Serial number : FOFO 15 # Orientation to the Weat State : False 16 robot.setOrientation (direction[ "West"]) Orientation : 1 17 robot.move(4) Type : Mobile 18 robot.display() X: 0 19 # Orientation to the North Y: 6 robot.setOrientation (direction[ "North"]) Serial number : FOFO 21 robot.move(6) State: False 22 robot.display ( ) Orientation : 2 23 # Orientation to the East Type : Mobile 24 robot.setOrientation (direction[ "East"]) X: 0 25 robot.move(14) Y: 6 26 robot.display ( ) Serial number : FOFO 27 # Orientation to the South State : False 28 robot.setOrientation (direction["South"]) Orientation : 3 29 robot.move(-8) Type : Mobile 30 robot.display ( ) X: 0 Y: 14 9 20

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_2

Step: 3

blur-text-image_3

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

Students also viewed these Databases questions