Geometry Calculator Write a program that displays the following menu: Geometry C
ID: 669605 • Letter: G
Question
Geometry Calculator Write a program that displays the following menu: Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit Enter your choice ( 1- 4): If the user enters 1, the program should ask for the radius of the circle and then display its area. Use the following formula: area = pr2 Use 3.14159 for p and the radius of the circle for r. If the user enters 2, the program should ask for the length and width of the rectangle and then display the rectangle’s area. Use the following formula: area = length * width If the user enters 3 the program should ask for the length of the triangle’s base and its height, and then display its area. Use the following formula: area = base * height * .5 If the user enters 4, the program should end. Input Validation: Display an error message if the user enters a number outside the range of 1 through 4 when selecting an item from the menu. Do not accept negative values for the circle’s radius, the rectangle’s length or width, or the triangle’s base or height.
Explanation / Answer
#include<iostream.h>
#include<math.h>
const float p=3.14159;
void main()
{
int choice;
cout<<"Geometry Calculator ";
cout<<"1.Calculate the Area of a Circle "
<<"2. Calculate the Area of Rectangle "
<<"3. Calculate the Area of Rectagle "
<<"4. Quit ";
<<"Enter your choice(1-4) ";
cin>> Choice;
switch(Choice)
{
case 1:
cout<<"Enter the radius of circle";
cin>> radius;
If (radius<=0)
cout<<"Wrong input. Please enter a positive number";
Area= p*r2 ;
cout<<"Area of Circle is "<<Area;
break;
case 2:
cout<<"Enter Length and width of Rectangle";
cin>>Length>>Width;
If (Length<=0 &&Width<=0)
{cout<<"Wrong input. Please enter a positive number";}
AreaofRec=Length*Width;
cout<<"Area of Rectangle is"<<AreaofRec;
break;
case 3:
cout<<"Enter length of base and height";
cin>>base>>height;
If (base<=0 && height<=0)
cout<<"Wrong input. Please enter a positive number";
Area=base*height*0.5;
break;
case 4:
cout<< "Quit the Program"<<Quit;
cin>>Quit;
break;
Default:
cout<<"Invalid input. Please select a number (1-4) only";
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.