Copy your class \"Robot\" from the previous question Create the getter and sette
ID: 3601082 • Letter: C
Question
Copy your class "Robot" from the previous question Create the getter and setter methods for the Robot class. In particular, write methods to get and set the values of the x, y, and heading attributes Name your functions the following getX getY getHeading setX setY setHeading The getters should return the corresponding attribute, and the setters should take in a value and set the attribute accordingly. (e.g., getX should return the x value for the robot, setX should take in an integer and set the x value to that integer) Answer: (penalty regime: 0 %) 1 class Robot public: int x,y; char heading; Robot(int start_x,lnt start_y, char start_heading) 4 7 x-start_x; y = start-y ; headingstart heading; 10 12 3; 13Explanation / Answer
Answer:
class Robot {
public:
int x,y;
char heading;
Robot(int start_x,int start_y, char start_heading) {
x = start_x;
y = start_y;
heading = start_heading;
}
void setX(int i) {
x = i;
}
void setY(int i) {
y = i;
}
int getX() {
return x;
}
int getY() {
return y;
}
void setHeading(char c) {
heading = c;
}
char getHeading() {
return heading;
}
};
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.