Answer to Question #279458 in C++ for Kyut

Question #279458

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:



1
Expert's answer
2021-12-14T07:02:38-0500
#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');	
}

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