Robot
models an n
-wheeled robot with m
ultrasonic sensors.
- The robot must always have a name to identify it.
- The number of wheels and ultrasonic sensors on the robot is fixed upon creation.
- Has an x and y position. The initial position is always (0, 0).
- Assume distance is in metres and angles are in radians.
Implement Robot
according to the following specification:
Method | Description | Usage | Exceptions |
---|---|---|---|
Robot(std::string const& name, int const& n) |
Constructs a robot with a name , n wheels, and no sensors. |
|
Prints to std::cerr if n is negative. |
Robot(std::string const& name, int const& n, int const& m) |
Constructs a robot with a name , n wheels, and m sensors. |
|
Prints to std::cerr if n or m is negative. |
std::string getName() |
Gets the name of the robot. |
|
None |
int getNumWheels() |
Gets the number of robot wheels. |
|
None |
int getNumSensors() |
Gets the number of robot sensors. |
|
None |
void setName(std::string const& name) |
Sets the name of the robot to the name provided by the argument. |
|
None |
void move(double x, double y) |
Moves the robot to the new position. |
|
None |
std::pair<double, double> localise() |
Gets the polar coordinates of the robot with respect to (0, 0). |
|
None |
In addition to the above specification, you must:
- Implement
const
-correctness for methods and member variables. - Mark the default constructor as
default
ordelete
. - Mark the destructor as
default
ordelete
. - Use initialiser lists where required.
- Use delegating constructors where possible.
- Have correct access specifiers.
Take the Robot
class from lab02-1 and extend it with the following specification:
Method | Description | Usage | Exceptions |
---|---|---|---|
Robot(Robot const& r) |
Copy constructor. |
|
None |
Robot(Robot&& r) |
Move constructor. |
|
None |
Robot& operator=(Robot const& r) |
Copy assignment. |
|
None |
Robot& operator=(Robot&& r) |
Move assignment. |
|
None |
static std::pair<double, double> cartesian_to_polar(std::pair<double, double> const& val) |
Converts a cartesian coordinate to polar coordinate. |
|
None |
friend std::ostream& operator<<(std::ostream& os, Robot const& r) |
Writes the name, number of wheels, number of sensors, cartesian coordinates, and polar coordinates of the robot. |
|
None |
friend std::istream& operator<<(std::istream& is, Robot& r) |
Inputs the x then y coordinates for the robot. It is equivalent to r.move(x, y) . |
|
None |
In addition to the above specification, you must:
- Implement
const
-correctness for methods and member variables. - Mark appropriate constructors, assignments, and destructor as
default
ordelete
. - Have correct access specifiers.
- Write more tests for the new methods.