Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A point on the two-dimensional plane can be represented by two numbers: an x- coordinate and a y- coordinate. For example, (4,5) represents a point

A point on the two-dimensional plane can be represented by two numbers: an x- coordinate and a y- coordinate. For example, (4,5) represents a point 4 units to the right of the vertical axis, and 5 units up from the horizontal axis. The sum of two points can be defined as a new point whose x coordinate is the sum of the x coordinates of the two points, and whose y coordinate is the sum of the y coordinates.

Complete the program below that uses a structure called point to model a point. Comments in the code tells you what you need to do. The program should define three points, and have the user input values to two of them. Then set the third point equal to the sum of the other two, and display the value of the new point.

Interaction with the program should look like this: Enter coordinates for p1 (use input format: x, y): 3, 4 Enter coordinates for p2 (use input format: x, y): 5, 7

Coordinates of p1 + p2 are: 8, 11

 #include  using namespace std; struct point { int xCo; //X coordinate int yCo; //Y coordinate }; //Sum function Prototype point sum(const point &a1, const point &a2); //Write the prototype for the showPoint function here int main() { point p1, p2, p3; //define 3 points char dummy[100]; cout << " Enter coordinates for p1 (use input format: x, y): "; //get 2 points cin >> p1.xCo >> dummy >> p1.yCo; cout << "Enter coordinates for p2 (use input format: x, y): "; cin >> p2.xCo >> dummy >> p2.yCo; p3 = sum(p1, p2); cout << "Coordinates of p1+p2 are: "; //display the sum //Call the showPoint function here cout << endl; return 0; } void showPoint(const point &p){ cout << p.xCo << ", " << p.yCo; } //define the sum function here 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

What is the investment income account of the balance of payments?

Answered: 1 week ago