Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

what is the mistake here? #include #include void get_corners(float x[], float y[]); int i; int ret; do { scanf(%lf,&x[i]; ret = scanf(%lf, &y[i]; } while(ret

image text in transcribedimage text in transcribed

what is the mistake here?

#include #include

void get_corners(float x[], float y[]); int i; int ret; do { scanf("%lf",&x[i]; ret = scanf("%lf", &y[i]; } while(ret >0); } int main(void) //define the main function { //declare the required variables char file[20]; float x[7],y[7];

//prompt the user to enter a file name printf("Enter a file name: "); scanf("%s",file);

//call the function get_corners by x_y_polygon.txt get_corners(file,x,y); }

//define the function get_corners void get_corners(char file[], float x[], float y[]) { FILE *fp; char file1[20]; int k =0,j=0,c=0; float i,area; fp = fopen(file,"r");

//check the file pointer if(fp==NULL) { //if fp is not null, enter into the else part } else { //use fscan to read the data from the file while(fscanf(fp,"%f",&i)==1) { c = c+1; //check the value of c if(c%2!=0) { //if c is not even, assign the value of i to array x and increment the counter k x[k]=i; k++; } //else part will execute when c is even else { //assign the value of i to array y and increment the j counter y[j] = i; j++; } }

//call the polygon_area function by x_y_polygon area= polygon_area(x,y,k);

//print the area of the polygon printf("Area of polygon = %.2f",area);

//prompt the user to enter the file name to write the data into file1 printf("Enter a file name to write the data: "); scanf("%s",file1); //call the output_corners function by x_y_polygon in order to write the data into file output_corners(file1,x,y,k);

//close the file fclose(fp); } }

//define the function polygon_area float polygon_area(float x[],float y[],int k) { //declaration and initilization float sum = 0.0,a,a1; int i;

//start the for loop for(i=0;i

//compute the absloute value of the variable sum a1 = fabs(sum);

//divide a1 by 2 to caculate the area of the polygon a = a1/2;

return a; }

//define the function output_corners void output_corners(char file1[],float x[],float y[],int k) { //declare a file pointer FILE *fp1; int i;

//open the file in write mode fp1 = fopen(file1,"w"); scanf("%lf", &i); //print characters in the file using fprint fprintf(fp1,"X\tY "); fscanf x[7](4-4-7-7-9-7-4) fscanf y[7](0-7.5-7.5-3-0-0-0-0) fprintf(fp1,"------------------");

//start the for loop for( i = 0;i

//write the data to the file using fprintf fprintf(fp1,"%.2f\t%.2f ",x[i],y[i]); }

//display the message printf("data is written into the file");

//close the file fclose(fp1);

}

2. Ifn points are connected to form a closed polygon as shown below, the area A of the polygon can be computed as Notice that although the illustrated polygon has only six distinct corners, n for this polygon is 7 because the algorithm expects that the last point, (xo, Je), will be a repeat of the initial point, o Yo (xi.yi) (Xo'yo) = (X6.ye) (X5JS) (X4.Y4) n=7 Programming Projects 445 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. 4 0 7.5 7.5 4 9 0 0 0 4 Implement the following functions get_corners Takes as parameters an input file, arrays x and y, and the with data from the file (ignoring any arrays' maximum size. Fills the arrays 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 arravs 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

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

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

How to find if any no. is divisble by 4 or not ?

Answered: 1 week ago

Question

Explain the Pascals Law ?

Answered: 1 week ago

Question

What are the objectives of performance appraisal ?

Answered: 1 week ago