side note : ( DHS is the currenncy used in my country so its similar to $. ) A l
ID: 3584187 • Letter: S
Question
side note : ( DHS is the currenncy used in my country so its similar to $. )
A land is defined by n points that are connected to form a closed polygon as shown below. The area A of the land can be computed as : < check below >
Notice that although the illustrated polygon has only six distinct corners, n for this polygon is 7 (i.e., n = no. of corners + 1) because the above equation expects that the last point, (x6, y6), will be a repeat of the initial point, (x0, y0).
The price of the one square meter of the land is calculated based on its area according to the following table:
Area (m2)
0.0
Area (m2)
0.0
Explanation / Answer
//program to calculate area of rectangle/cirlce/triangle using Cartesian coordinates entered by user int choice; float x1,y1,x2,y2,x3,y3,x4,y4,side_1,side_2,side_3,r,A,P; /*declare variables*/ //ask user for the choice of shape printf("Welcome to Cartesian geometry! Please choose your shape by entering its number: "); printf("Rectangle -> enter 1 "); printf("Circle -> enter 2 "); printf("Triangle -> enter 3 "); printf("Exit Program -> enter 4 "); scanf("%d", &choice); if (choice==1) /*The User enters the Cartesian coordinates of the rectangle*/ { printf("Please enter the coordinates for the rectangle from bottom left to right, then top right to left"); printf(" enter value for x1:"); scanf("%f", &x1); printf("enter value for y1:"); scanf("%f", &y1); printf("enter value for x2:"); scanf("%f", &x2); printf("enter value for y2:"); scanf("%f", &y2); printf("enter value for x3:"); scanf("%f", &x3); printf("enter value for y3:"); scanf("%f", &y3); printf("enter value for x4:"); scanf("%f", & x4); printf("enter value for y4:"); scanf("%f", &y4); side_1=pow(pow((x2-x1), 2) + pow((y2-y1), 2), .5); /*Calculate the length of side 1 using the distance formula*/ side_2=pow(pow((x3-x2), 2) + pow((y3-y1), 2), .5); /*Calculate the length of side 2 using the distance formula*/ A= side_1*side_2; printf("The Area is %f", A); /* Display the Area and Perimeter*/ P=2*(side_1+side_2); printf("The Perimeter is %f", P); } if (choice==2) { printf("You have chosen a cirlce, please enter the coordinates of the centre, then a point on the circle "); /* User enters the coordinates of the circle*/ printf("enter value for x1 "); scanf("%f", &x1); printf("enter value for y1 "); scanf("%f", &y1); printf("enter value for x2 "); scanf("%f", &x2); printf("enter value for y2 "); scanf("%f", &y2); r=pow(pow((x2-x1), 2) + pow((y2-y1), 2), .5); /* Calculate radius using the distance formuala*/ A=3.141*(pow(r, 2)); printf(" the area is %f", A); /* Display Area and Perimeter*/ P=2*3.141*r; printf(" the perimeter is %f", P); } if (choice==3) { printf("You have chosen a triangle, please enter in the coordinates of its vertices from bottom left to right, then top."); /*User enters coordiantes for the triangle*/ printf(" Enter value for x1"); scanf("%f", &x1); printf(" please enter value for y1:"); scanf("%f", &y1); printf(" please enter value for x2:"); scanf("%f", &x2); printf(" please enter value for y2:"); scanf("%f", &y2); printf(" please enter value for x3:"); scanf("%f", &x3); printf(" please enter value for y3:"); scanf("%f", &y3); side_1=pow(pow((x2-x1), 2) + pow((y2-y1), 2), 0.5); /*Calculate length of side 1*/ side_2=pow(pow((x3-x2), 2) + pow((y3-y2), 2), 0.5); /*Calculate length of side 2*/ side_3=pow(pow((x3-x1), 2) + pow((y3-y1), 2), 0.5); /*Calculate length of side 3*/ A=0.25*pow(pow(pow(side_1, 2) + pow(side_2, 2) + pow(side_3, 2), 2) - 2*(pow(side_1, 4) + pow(side_2, 4) + pow(side_3, 4)), 0.5); /*Area of triangle using Heron's formula*/ printf("the area is %f", A); /* Display the Area and Perimeter*/ P= side_1 + side_2 + side_3; printf("the perimeter is %f", P);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.