In: Computer Science
Define the following class:
class XYPoint {
public:
// Contructors including copy and default constructor
// Destructors ? If none, explain why
double getX();
double getY();
// Overload Compare operators <, >, ==, >=, <=, points are compare using their distance to the origin: i.e. SQR(X^2+Y^2)
private: double x, y;
};
#include <iostream> #include <cmath> using namespace std; class XYPoint { public: XYPoint(double x, double y) : x(x), y(y) {} XYPoint() {} XYPoint(XYPoint& other) { x = other.x; y = other.y; } ~XYPoint() {} double getX(); double getY(); // Overload Compare operators <, >, ==, >=, <=, points are compare using their distance to the origin: i.e. SQR(X^2+Y^2) bool operator<(const XYPoint &rhs) const; bool operator>(const XYPoint &rhs) const; bool operator<=(const XYPoint &rhs) const; bool operator>=(const XYPoint &rhs) const; bool operator==(const XYPoint &rhs) const; double distance() const { return sqrt(x*x + y*y); } private: double x, y; }; double XYPoint::getX() { return 0; } double XYPoint::getY() { return 0; } bool XYPoint::operator<(const XYPoint &rhs) const { return distance() < rhs.distance(); } bool XYPoint::operator>(const XYPoint &rhs) const { return distance() > rhs.distance(); } bool XYPoint::operator<=(const XYPoint &rhs) const { return distance() <= rhs.distance(); } bool XYPoint::operator>=(const XYPoint &rhs) const { return distance() >= rhs.distance(); } bool XYPoint::operator==(const XYPoint &rhs) const { return distance() == rhs.distance(); } int main() { // your test code.. return 0; }