Answer to Question #252946 in C++ for aro

Question #252946

program that computes the area of either a rectangle, a circle or a  right-angled triangle. The program should display a menu that enables the user to select the  type of figure whose area he/she wants to compute. Depending on the user’s choice, the  program should prompt for the dimensions and perform the computations. The output should  be: - The type of figure, the dimensions and the area. Define three functions: - one to  compute the area of a rectangle, one the area of a circle and one the area of a triangle. NB: 1. The calculation should be for only one figure at any one time.  

 2. Computations should be done in the user-defined functions.




1
Expert's answer
2021-10-18T06:44:52-0400
#include <iostream> 
#include <string> 
using namespace std; 


double computeAreaRectangle(double a,double b){
	return a*b;
}
double computeAreaCircle(double radius){
	const double PI=3.14159265359;
	return PI*radius*radius;
}
double computeAreaTriangle(double base,double perpendicular){
	return (1.0/2.0)* base * perpendicular;
}
int main(){ 
	int ch=-1;
	double a,b,radius,base,perpendicular;
	while(ch!=4){
		cout<<"1. Compute the area of a rectangle\n";
		cout<<"2. Compute the area of a circle\n";
		cout<<"3. Compute the area of a triangle\n";
		cout<<"4. Exit\n";
		cout<<"Your choice: ";
		cin>>ch;


		switch(ch){
		case 1:
			{
				cout<<"Enter a rectangle's side 1: ";
				cin>>a;
				cout<<"Enter a rectangle's side 2: ";
				cin>>b;
				cout<<"The area of a rectangle: "<<(computeAreaRectangle(a,b))<<"\n";
			}
			break;
		case 2:
			{
				cout<<"Enter a circle's radius: ";
				cin>>radius;
				cout<<"The area of a circle: "<<(computeAreaCircle(radius))<<"\n";
			}
			break;
		case 3:
			{
				cout<<"Enter a triangle's base: ";
				cin>>base;
				cout<<"Enter a triangle's perpendicular: ";
				cin>>perpendicular;
				cout<<"The area of a triangle: "<<(computeAreaTriangle(base,perpendicular))<<"\n";
			}
			break;
		case 4:
			{
				//exit
			}
			break;
		}


	}


	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