Answer to Question #174692 in C++ for sara

Question #174692

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.


1
Expert's answer
2021-03-23T06:07:29-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS