Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Geometry Calculator Write a program that displays the following menu: Geometry C

ID: 670300 • 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>
#include <math.h>
#include <iomanip>

using namespace std;
int main()
{
int choice=0;
double rectangle_area, radius, base,breadth, length, height;
double circle_area, triangle_area;
const double PI = 3.14159;


while (choice<=3)
{
cout << "1 calculate the area circle" << endl;
cout << "2 calculate the area of rectangle" << endl;
cout << "3 calculate the area of triangle" << endl;
cout << "4 quit" <<endl;
cout << "Choose Your option : ";
cin >> choice;
cout << endl;

switch (choice)
       {
case 1:
cout << "enter the radious of a circle ";
cin >> radius;
  
circle_area= PI * radius * radius;
cout << "area of the circle is " << circle_area << endl;
break;

case 2:
cout << "enter the breadth of a rectangle"<< endl;
cin >> breadth;
cout << "enter the length of the rectangle" << endl;
cin >> length;
  
rectangle_area = breadth*length;
cout << "Rectangular Area =" << rectangle_area << endl;
break;

case 3:
cout << "enter the base of a triangle" << endl;
cin >> base;
cout << "enter the height of a triangle" << endl;
cin >> height;
  
triangle_area = (base * height)/2;

cout << "Triangle Area=" << setprecision(2)<<triangle_area << endl;

break;

default :
cout << "program quit" << endl;
break;
  
       }
}
return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote