Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

UsingC++ Thanks for Question1 and 2. Question 1 Every Robothas anx position ypos

ID: 3730374 • Letter: U

Question

UsingC++ Thanks for Question1 and 2.

Question 1 Every Robothas anx position yposition, and a heading. We want to represent these attributes of the Rcbot by data members in the class Create a class "Robot"wth the following public att lbutes: * an Integer x for the robor'sx postion Not answered Mark 0.00 out of 1.00 an integer y for the robor'sy position Y Flag question ter heading far th a charac robat's heading I'N, 'S,E,W Then, add a public constructor that takes * an int start an int starty a char start heading and sets the robat's attributes. Ars wer: (penalty regime:0%; In general It is better practice to make class data members private and only allow the user of the class to access them through setter and getter methods. We do this so that we can have more control over what values attributes are setto. Question 2 Not answered Someone might accldentally do something like this Robot bb8- Robotio, D, 'N b8.heading: Mark 0,00 out of 1.00 Flag question y ony allawing the heading atribute ta bn changed via the setter, far exampls, we culd ensure that heading is always 'N,'S,E or W hb9.setHeadirg? Far this question, change the x, y and heading attributes so that they have the private modifier Then, create the getter and setter methods for the Robot class. In particular, write methods to ge and set the values of the x, y, and heading attributes. Name your functions the fellowing: * gebx gety getHeading sotx sct setHeading The getters should return the corresponding atribute, and the setters should take in a value and se the attribute accordingy te.g, getx should return the x value for the robot sex should take in an integer and set the x value to that integer) Answer: (penalty regime 0 % 1 IV/COPY CODE FROM QUESTION 1

Explanation / Answer

The solution for the above question is given below.

================================================

I kept the class definitions as simple as possible, if there is anything else do let

me know in comments.

================================================

Question 1 : CODE TO COPY BELOW

class Robot {

public:

    int x;
    int y;
    char heading;
  
public:

    Robot(int start_x, int start_y, char start_heading){
      x = start_x;
      y = start_y;
      heading = start_heading;
    }

};

================================================

Question 2 : CODE TO COPY BELOW

class Robot {

private:

    int x;
    int y;
    char heading;
  
public:

    Robot(int start_x, int start_y, char start_heading){
      x = start_x;
      y = start_y;
      heading = start_heading;
    }
  
    int getX(){
      return x;
    }
  
    int getY(){
      return y;
    }
  
    char getHeading(){
      return heading;
    }
  
    void setX( int _x){
      x = _x;
    }
  
    void setY( int _y){
      y = _y;
    }
  
    void setHeading( char _heading ){
      heading = _heading;
    }

};