Project 15

two-dimentional array & user defined function (100 points)


side[0][0] = 5.000    side[0][1] = 8.000    side[0][2] = 7.000
side[1][0] = 13.00    side[1][1] = 14.00    side[1][2] = 15.00
side[2][0] = 9.000    side[2][1] = 40.00    side[2][2] = 41.00 
side[3][0] = 8.000    side[3][1] = 7.000    side[3][2] = 13.00 

This matrix indicates that each row is a set of triangle sides.

area[i] = tri_area( side[i][0], side[i][1], side[i][2] )

tri_area is the name of the user defined function. The parameters side[i][0], side[i][1], side[i][2] are the sides of each individual triangle. An example prototype for this function would be.

float tri_area(float a, float b, float c)
Hero's formula
if a, b, and c are the sides of the triangle then,
s = (a + b + c) / 2 and the area = sqrt(s(s-a)(s-b)(s-c))

Using the sample output as an example, after you exit the loop to calculate the areas you should have the following one-dimentional array filled.

area[0] = 17.32   area[1] = 84.00   area[2] = 180.0   area[3] = 24.25



Sample output
How many triangle do you want to find the area of? : 4

Clear Screen Here

Entering sides for triangle 1
==================================

Please enter side 1 : 5
Please enter side 2 : 8
Please enter side 3 : 7

Clear Screen Here

Entering sides for triangle 2
==================================

Please enter side 1 : 13
Please enter side 2 : 14
Please enter side 3 : 15

Clear Screen Here

Entering sides for triangle 3
==================================

Please enter side 1 : 9
Please enter side 2 : 40
Please enter side 3 : 41

Clear Screen Here

Entering sides for triangle 4
==================================

Please enter side 1 : 8
Please enter side 2 : 7
Please enter side 3 : 13


Clear Screen Here

Area of Triangle Report
=============================================
Triangle   Side 1   Side 2   Side 3   Area
=============================================
1          5.000    8.000    7.000    17.32
2          13.00    14.00    15.00    84.00
3          9.000    40.00    41.00    180.0
4          8.000    7.000    13.00    24.25
=============================================
                              Total : 305.57