The 3 vertices of the triangle are to be entered as x and y coordinates which sh
ID: 3655622 • Letter: T
Question
The 3 vertices of the triangle are to be entered as x and y coordinates which should be of type double. It would 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 and c, you can compute the area of the 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.
Please do not copy&paste from forums, I could have done that myself too, you know!
Thanks.