In this exercise, you create a Triangle class and a program that uses the Triangle class to

Question:

In this exercise, you create a Triangle class and a program that uses the Triangle class to instantiate a Triangle object. 

a. If necessary, create a new project named Intermediate17 Project and save it in the Cpp8\Chap15 folder. Create a Triangle class. Enter the class definition in a header file named Intermediate17 Triangle.h. The class should include a void method that allows the program to set the triangle’s dimensions. The method should verify that all of the dimensions are greater than 0.0 before assigning the values to the private data members. The class also should include two value-returning methods. One value-returning method should calculate the area of a triangle, and the other should calculate the perimeter of a triangle. The formula for calculating the area of a triangle is 1/2 * b * h, where b is the base and h is the height. The formula for calculating the perimeter of a triangle is a + b + c, where a, b, and c are the lengths of the sides. Determine the appropriate variables to include in the class. Be sure to include a default constructor that initializes the variables. 

b. Create a program that prompts the user for the triangle’s dimensions and then displays the triangle’s area and perimeter amounts. Enter your C++ instructions in a source file named Intermediate17.cpp. Display the amounts with zero decimal places. Also enter appropriate comments and any additional instructions required by the compiler. Save and then run the program. Test the program appropriately

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: