Question: In C++ 1. Define the class Point2D that represents an ordered pair (x, y) in a rectangular coordinate system. The Point2D class has two private
In C++
1. Define the class Point2D that represents an ordered pair (x, y) in a rectangular coordinate system. The Point2D class has two private data members x(double), y(double). The class must have a default constructor as well as a constructor with parameters. Have a get/set methods for the private data members.
a) Include the function distance () that returns the distance of the point from the origin using the formula sqrt x^2 + y^2.
b) Overload the insertion (<<) operator for the Point2D class such that when applying cout to a point object it displays the ordered pair (x , y), where x is the value of the x component and y is the value of the y component of the object.
c) Overload the operator less than (<) as a nonmember function with the header
bool operator< (Point2D p1, Point2D p2)
the operator returns true if P1s distance from the origin is less that p2s distance from the origin.
d) Test the Point2D class by writing a main function where you declare two Point2D objects using the constructor with parameters.
Use the overloaded operator (<<) to display the points.
Call the distance function and display the distance of the points from the origin.
Finally use the operator < to compare the two objects and display the smaller object.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
