1. Write a C++ program that calculates the right triangle's hypotenuse c=√a+b
2. Do include the header file < cmath >
3. Run the code.
4. Make sure you save your code and take a screenshot of both the code and the results.
#include <iostream>
#include <cmath>
using namespace std;
class Triangle{
public:
float a, b;
Triangle(){
}
Triangle(float x, float y){
this->a = x;
this->b = y;
}
float hypotenuse(){
return sqrt(a * a + b * b);
}
};
int main(){
float a, b;
cout<<"Input the sides of the triangle:\n";
cin>>a;
cin>>b;
Triangle T(a, b);
cout<<"The hypotenuse is "<<T.hypotenuse();
return 0;
}
Comments
Leave a comment