C Overload Following Operators Xypoint Class Semantics Operators Based Distance Origin Ie Q37059976

C++

Overload the following operators for the XYPoint class: ==,<, >, <=, >=, !

Semantics of these operators are based on their distance to theorigin: ie: two points are equal if their distance to the origin(0,0) is the same, one point is less than the other if its distanceto the origin is less than the other’s.

! is only true for the origin point (0,0)


Solution


#include <iostream>#include <cmath>using namespace std;class XYPoint {private: double x, y;public: double distanceToOrigin() const { return sqrt(x*x + y*y); }

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.