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

If n points are connected to form a closed polygon as shown below, the area A of

ID: 3545633 • Letter: I

Question

If n points are connected to form a closed polygon as shown below, the area A
of the polygon can be computed

Represent the (x, y) coordinates of the connected points as two arrays of
at most 20 type double values. For one of your tests, use the following data
set, which defines a polygon whose area is 25.5 square units.

Implement the following functions:
get_cornersâTakes as parameters an input file, arrays x and y, and the
arraysâ maximum size. Fills the arrays with data from the file (ignoring any
data that would overflow the arrays) and returns as the function value the
number of (x, y) coordinates stored in the arrays.
output_cornersâTakes as parameters an output file and two type double
arrays of the same size and their actual size, and outputs to the file the
contents of the two arrays in two columns.
polygon_areaâTakes as parameters two arrays representing the (x, y) coor-
dinates of the corners of a closed polygon and their actual size and returns
as the function value the area of the closed polygon.

x y
4 0
4 7.5
7 7.5
7 3
9 0
7 0
4 0

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>
int main(int argc, char **argv[])
{
int size = 0;
char fileName[] = "pointData.txt";
double sum=0;
int i;
FILE *instream=NULL;
instream = fopen(fileName, "r");
fscanf(instream,"%d",&size);
double x[size];
double y[size];
for(i=0; i<size; i++){
fscanf(instream,"%lf",&x[i]);
fscanf(instream,"%lf",&y[i]);}
fclose(instream);
for(i=0; i<size; i++){
sum+=(((x[i])*(y[i+1]))-((x[i+1])*(y[i])));}
sum/=2.0;
printf("Area of the polygon is: %.4f ", sum);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote