Question: Computer Science/CIS 150 C++ Create a struct, Triangle, with the following attributes: base (double), height (double), and area (double). Write a function computeArea() that has

Computer Science/CIS 150 C++

Create a struct, Triangle, with the following attributes: base (double), height (double), and area (double).

Write a function computeArea() that has a single Triangle structure as a parameter and returns the triangle’s area (base * height / 2.0).

Write a main program that creates an array to hold 5 instances of Triangle. Use a for loop to ask the user for base and height dimensions for each instance and store in the struct’s appropriate attributes. Call computeArea() to calculate then store its area in the struct’s attribute.

Write a max function , passing the array as a parameter, to determine which Triangle has the greatest area, returning the index number of that triangle.

Finally, display on the console the base, height, and area of all triangles, each on a separate line.  All numbers are to be displayed to two decimal places.  Put a comment after the largest one(s) to indicate it is largest.

You must use separate source files for main, max, and computeArea.  You may use the following data to test your program (outside of your test plan) but MUST use different data in your test plan.

Sample output:

2.00 x 4.00 has area 4.00

1.00 x 6.00 has area 3.00

2.50 x 4.25 has area 5.31 – largest

4.00 x 0.05 has area 0.10

0.99 x 0.99 has area 0.49

Step by Step Solution

3.48 Rating (165 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To solve the problem of creating a program in C that manages the area of triangles and identifies the largest one lets break down the task into smalle... View full answer

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 Programming Questions!