The area of a triangle whose sides a, b, and c can be computed by the formula:
π¨πππ ππ π»πππππππ = βπ ((π β π)(π β π)(π β π))
where S = (a+b+c)/2. On the other hand, the hypotenuse of a right triangle can be computed using the
formula:
#include<iostream>
#include<cmath>
using namespace std;
void Menu()
{
cout<<"\nWhat do you want to compute?\n"
<<"A - Area of a triangle\n"
<<"H - Hypotenuse of a right triangle\n"
<<"E - Exit program"
<<"Your choice: ";
}
void countArea()
{
double a,b,c;
cout<<"Please, enter a value for side a: ";
cin>>a;
cout<<"Please, enter a value for side b: ";
cin>>b;
cout<<"Please, enter a value for side c: ";
cin>>c;
double S=(a+b+c)/2;
double area=sqrt(S*(S-a)*(S-b)*(S-c));
cout<<"The area of yor triangle is "<<area;
}
void countHypotenuse()
{
double a,b,c;
cout<<"Please, enter a value for side a: ";
cin>>a;
cout<<"Please, enter a value for side b: ";
cin>>b;
double hyp= sqrt(a*a+b*b);
cout<<"The hypotenuse of yor right triangle is "<<hyp;
}
int main()
{
char ch;
do
{
Menu();
cin>>ch;
switch(ch)
{
case 'A':case 'a':
{
countArea();
break;
}
case 'H':case 'h':
{
countHypotenuse();
break;
}
}
}while(ch!='E'&&ch!='e');
}
Comments
Leave a comment