Question: Define a structure called Point which will represent an x,y coordinate. Point should have 2 members, x and y, stored as doubles. Request x,y coordinates

Define a structure called Point which will represent an x,y coordinate. Point should have 2 members, x and y, stored as doubles. Request x,y coordinates from the user. The program should collect x,y points until the user enters "q" or "Q". The user should be allowed to store as many points as they would like. (i have got this part, now i need help implemeting the function part)

#include #include

using namespace std;

struct point { double x; double y; };

int main() { vector points; cout << "Enter as many points as you want(q or Q to quit): "; double x, y; while(cin >> x) { if((char)x == 'q' || (char)x == 'Q') { break; } cin >> y; point p; p.x = x; p.y = y; points.push_back(p); } // print all points cout << "You entered" << endl; for(int i = 0; i < points.size(); ++i) { cout << "x = " << points[i].x << ", y = " << points[i].y << endl; } return 0; }

Write a function that calculates the average x,y point from a list of points passed to the function and return a new point containing this value. Pass your user collected points to this function. If 0 points are passed to this function, return a point containing 0,0 as its coordinates.

note:i need help with function. please keep the codes very simple. i am having trouble passing the values to a function.

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!