Question: In C++ Four doubles are read from input, where the first two doubles are the x and y values of point1 and the second two

In C++ Four doubles are read from input, where the first two doubles are the x and y values of point1 and the second two doubles are the x and y values of point2. Define the function to overload the - operator.

Ex: If the input is 13.5 15.0 4.0 4.5, then the output is:

(13.5, 15) - (4, 4.5) = (9.5, 10.5)

Note: The difference of two points is:

the difference of the x values of the points

the difference of the y values of the points

#include using namespace std;

class Point { public: Point(double xCoord = 0.0, double yCoord = 0.0); void Print() const; Point operator-(Point rhs); private: double xCoordinate; double yCoordinate; };

Point::Point(double xCoord, double yCoord) { xCoordinate = xCoord; yCoordinate = yCoord; }

// No need to accommodate for overflow or negative values

// Your Code Goes Here.

void Point::Print() const { cout << xCoordinate << ", " << yCoordinate; }

int main() { double xCoord1; double yCoord1; double xCoord2; double yCoord2; cin >> xCoord1; cin >> yCoord1; cin >> xCoord2; cin >> yCoord2; Point point1(xCoord1, yCoord1); Point point2(xCoord2, yCoord2); Point difference = point1 - point2; cout << "("; point1.Print(); cout << ") - ("; point2.Print(); cout << ") = ("; difference.Print(); cout << ")" << endl; return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!