Project 77: Sum of Distances from a Point

For the graph above, the point PQ is at (4, 2).  There are four other points on the graph (1, 2), (3, 4), (2, 5), and (4, 5).  The calculations shown below are to solve for the sum of the distances between the points and PQ.

Point 1: (1, 2)  The distance from PQ is 3

Point 2: (3, 4).  The distance from PQ is 2.23 

Point 3: (2, 5).  The distance from PQ is 3.61

Point 4: (4, 5).  The distance from PQ is 3


Sum of Distances = 3 + 2.23 + 3.61 + 3 = 11.84


Project 77: Variables 'x1', 'y1', 'x2', 'y2', 'x3', 'y3', 'x4', 'y4', 'p', and 'q' are all initialized.  There is a working method available called distance.

Example: x1, y1 is the coordinates of point 1

p is the x-coordinate of the desired point (4 for the example above)

q is the y-coordinate of the desired point (2 for the example above)

distance(x1, y1, x2, y2) returns the distance between the two points.

distance(4, 2, 3, 4) returns 2.23

Task: Appropriately initialize the value of 'sumDist' which represents the sum of the distances of the four points from the desired point PQ.

**If your code works for 5 test cases, you can enter your e-mail address

Universal Computational Math Methods:

pow(5,2) returns 25.0

abs(-3.0) returns 3

sqrt(49.0) returns 7.0