Question: C++ Program Write a program that reads in the coordinates of the three vertices of a triangle and prints out the area of the triangle.

C++ Program

Write a program that reads in the coordinates of the three vertices of a triangle and prints out the area of the triangle. The input will come as pairs of numbers separated by a space and may include decimal values.

To calculate the area of the triangle, use Heron's formula:

A=sqrt s(s-a)(s-b)(s-c)

Where a, b, and c are the lengths of the sides and s is the semi perimeter: (a + b + c)/2.

To calculate the length of each side, you will need to use the distance formula:

Length = sqrt (x sub 2 - x sub 1)^2 + (y sub2 - y sub1)^2

Sample run:

The given input represents a point at 1, 1 another at 4, 1 and a third at 1, 5.

Enter x y for point 1: 1 1 Enter x y for point 2: 4 1 Enter x y for point 3: 1 5 The area of the triangle is 6

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!