Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN C++ ONLY INSTRUCTIONS Create a project that utilizes a class to store the two

ID: 3582378 • Letter: I

Question

IN C++ ONLY

INSTRUCTIONS

Create a project that utilizes a class to store the two short sides of a right triangle and calculate its hypotenuse. The class should have gets and sets associated with private variables for the short sides. The class should have the ability to store the value of the hypotenuse, calculate the hypotenuse, and print out the information about the right triangle (the lengths of all three sides in a concise statement).

Create a main.cpp within the project to query a user for the values of the two short sides. It should then use the right triangle class object to calculate the hypotenuse and print out the right triangle information.

Explanation / Answer

#include <iostream>
#include <cmath> //for sqrt() function
#include <iomanip> //for setprecision()
using namespace std;

class RightAngleTriangle
{
   private:
   double base;
   double height;
  
   public:
   void setBase(double base) //set and get methods
   {
       this->base = base;
   }
   void setHeight(double height)
   {
       this->height = height;
   }
   double getBase()
   {
       return base;
   }
   double getHeight()
   {
       return height;
   }
   double calculateHypotenuse()
   {
   double hypotenuse = sqrt(base*base + height*height);
       return hypotenuse;
   }
   void printInfo()
   {
       cout<<" Right Angle Triangle :";
       cout<<" Base : "<<base<<" Height : "<<height<<" Hypotenuse : "<<calculateHypotenuse();
   }
  
};
int main()
{
   RightAngleTriangle t ;
   t.setBase(4.4);
   t.setHeight(5.1);
   cout<<fixed<<setprecision(2);
   t.printInfo();
  
   return 0;
}

output: