Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part 1 Define two structs in a header file called Plot.h: Point x (double) y (do

ID: 3542261 • Letter: P

Question

Part 1


Define two structs in a header file called Plot.h:

Point

x (double)

y (double)

Plot

points (array of up to 20 Points)

size (int, current number of Points in the Plot)


Part 2


Create two functions in a C source file called Plot.c:

addPoint (to be completed as a class)

Parameters:

Plot = The Plot to add the point to.

x (double) = The x coordinate of the point to be added.

y (double) = The y coordinate of the point to be added.

Adds a point with the given values to the end of the Plot.

Returns: The updated Plot.

getCenter

Parameters:

Plot = The Plot to find the center of.

Finds the point at the center of the Plot (i.e. average x and y values).

Returns: The point at the center of the Plot.

getDistanceFromCenter

Parameters:

Plot = The Plot containing the point.

index (int) = The index of the point in the Plot that the distance will be calculated for.

Calculate the distance from the point at the given index and the center of the Plot.

Hints:

square root = sqrt function

Need to #include <math.h>

Might need to compile with the -lm flag.

Distance Formula (http://en.wikipedia.org/wiki/Distance#Geometry)

Returns: The distance of the point at the given index to the center of the Plot.


Explanation / Answer

//FIRST FILE Plot.h


typedef struct {

double x,y;

}Point;


typedef struct{

Point points[20];

int size;

}Plot;