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

You are to write a program to compute the lengths of the sides of the triangle a

ID: 3655526 • Letter: Y

Question

You are to write a program to compute the lengths of the sides of the triangle and the area of the triangle. The three vertices of the triangle are to be entered as x and y coordinates which should be of double. It should be convenient to store all 6 vertices in separate variables. After reading the vertices your program should print the distances from the first point to the second, from the second to the third and from the third to the first. It would probably be convenient to store these distances in 3 double variables. These distances are the lengths of the sides of the triangle. The formula for distance is: distance = sqrt ( (x1 - x2) * (x1 - x2) +(y1 - y2)* (y1 - y2) ) Assuming the 3 distances are a, b, c you can compute the area of triangle using this formula: area = 0.25 * sqrt ( (a + b + c) * (-a + b + c) * (a - b + c) * (a + b -c) ) Your program needs to implement 2 user-defined functions. One function needs to compute the distance between 2 vertices. The second function needs to compute the area of a triangle.

Explanation / Answer

#include #include using namespace std; double distance(double x1, double y1, double x2,double y2){ return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)); } double triangleArea(double a, double b,double c){ return (0.25*sqrt((a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c))); } int main(){ double x1,x2,x3; double y1,y2,y3; double d1,d2,d3; double area; coutx1>>y1; coutx2>>y2; coutx3>>y3; d1=distance(x1,y1,x2,y2); d2=distance(x1,y1,x3,y3); d3=distance(x3,y3,x2,y2); area=triangleArea(d1,d2,d3); cout
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