Robot.h: Tutorial: Object-Oriented Programming Using C++ Tutorial
Robot.h: Tutorial: Object-Oriented Programming Using C++ Tutorial
h
! Define an object to represent the position of a mobile robot on a 2- #define PI 3.14159265
dimensional grid and the direction in which it is facing.
! Write a constructor method. class robot {
! Write methods to move the robot forwards and backwards by a private:
certain distance. double x;
! Write a method to rotate the robot clockwise by a certain number double y;
of degrees. double r; // rotation clockwise wrt due north
! Write a method to print the position and orientation of the robot. public:
! Write a test program that makes the robot traverse a rectangle robot ();
and return to its starting point. The program should print the void forwards (double distance);
position of the report after each movement. void backwards (double distance);
void rotate (double degrees);
void print_position ();
Hint: the following can be used to calculate sine and cosine where x (a };
double) is in degrees:
#define PI 3.14159265
#include <math.h>
sin(x * PI / 180.0)
cos(x * PI / 180.0)