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

Q5. (15 points) (Area and perimeter) Ask the user for three points (e.g. (Xi, yi

ID: 3586188 • Letter: Q

Question

Q5. (15 points) (Area and perimeter) Ask the user for three points (e.g. (Xi, yi), (x2, V2), (xs, ys)). Write two functions "area" and "perimeter" that calculate the area and perimeter when the three points are given. All numbers and return values should be of type double. Use the following formulas to calculate area and perimeter: lx10%-%) + x20%-yl) + X3(y1-y2)| side,-V (x2-x1)2 + (y2-y1)2 perimeter = side, + side2 + side3 area where "I I" shows absolute value in the formula for "area". At the end, print the following message Triangle points: (x1,y1), (x2, y2), and (x3, y3) and area

Explanation / Answer


C code:

#include <stdio.h>
#include <math.h>


void AreaCalculationThreePoints(float axValue, float ayValue, float bxValue, float byValue, float cxValue, float cyValue)
{
float periValue,areaValue;
float AValue = sqrt((double)(bxValue-axValue) * (bxValue-axValue) + (byValue-ayValue) * (byValue-ayValue));
float BValue = sqrt((double)(bxValue-cxValue) * (bxValue-cxValue) + (byValue-cyValue) * (byValue-cyValue));
float CValue = sqrt((double)(axValue-cxValue) * (axValue-cxValue) + (ayValue-cyValue) * (ayValue-cyValue));


  
float sValue = (AValue + BValue + CValue) / 2;

periValue = AValue + BValue + CValue;

areaValue = sqrt( sValue * (sValue-AValue) * (sValue-BValue) * (sValue-CValue));

printf(" Perimeter of the three points : %.4f", periValue);
printf(" Area of the three points: %.4f", areaValue);
  
  
}

int main()
{
  
float axValue, ayValue, bxValue, byValue, cxValue, cyValue;
float periValue, areaValue;

printf("Enter First Point A - X Value: ");
scanf("%f", &axValue);

printf("Enter First Point A - Y Value: ");
scanf("%f", &ayValue);

printf("Enter Second Point B - X Value: ");
scanf("%f", &bxValue);

printf("Enter Second Point B - Y Value: ");
scanf("%f", &byValue);

printf("Enter Third Point C - X Value: ");
scanf("%f", &cxValue);

printf("Enter Third Point C - Y Value: ");
scanf("%f", &cyValue);

AreaCalculationThreePoints(axValue, ayValue, bxValue, byValue, cxValue, cyValue);
return 0;

}

Output :

gcc version 4.6.3

Enter First Point A - X Value: 3
Enter First Point A - Y Value: 2
Enter Second Point B - X Value: 3
Enter Second Point B - Y Value: 4
Enter Third Point C - X Value: 2
Enter Third Point C - Y Value: 5

Perimeter of the three points : 6.5765
Area of the three points: 1.0000