Question: Four integers are read from input, where the first two integers are the x and y values of point1 and the second two integers are

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

Ex: If the input is 13 9 7 2, then the output is:

(13, 9) + (7, 2) = (20, 11)

Note: The sum of two points is:

the sum of the x values of the points

the sum of the y values of the points

Code: C++ ONLY

#include using namespace std;

class Coordinate2D { public: Coordinate2D(int x = 0, int y = 0); void Print() const; Coordinate2D operator+(Coordinate2D rhs); private: int xCoordinate; int yCoordinate; };

Coordinate2D::Coordinate2D(int x, int y) { xCoordinate = x; yCoordinate = y; }

// No need to accommodate for overflow or negative values

// CODE GOES HERE // Do not change any of the other code

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

int main() { int x1; int y1; int x2; int y2; cin >> x1; cin >> y1; cin >> x2; cin >> y2; Coordinate2D point1(x1, y1); Coordinate2D point2(x2, y2); Coordinate2D sum = point1 + point2; cout << "("; point1.Print(); cout << ") + ("; point2.Print(); cout << ") = ("; sum.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!