Computer Science/CIS 150 C++ Create a struct, Triangle, with the following attributes: base (double), height (double), and
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 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
Vector Mechanics for Engineers Statics and Dynamics
ISBN: 978-0073212227
8th Edition
Authors: Ferdinand Beer, E. Russell Johnston, Jr., Elliot Eisenberg, William Clausen, David Mazurek, Phillip Cornwell