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
Step: 1
include include includetriangleh include using namespace std int mai...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started