Question: Write a program that displays the following menu with the following format: Geometry Calculator Calculate the Area of a Circle Calculate the Area of a
Write a program that displays the following menu with the following format:
Geometry Calculator
Calculate the Area of a Circle
Calculate the Area of a Rectangle
Calculate the Area of a Triangle
Calculate the Area of a Trapezoid
Calculate the Area of a Sphere
Exit
Enter your Choice (1-6):
Using a Switch statement for the users menu choice, calculate the area for the shape selected.
For a circle, the program must prompt the user radius of the circle. The program will calculate the area and display the area. For the rectangle, the program must prompt the user for the length and width of the rectangle. Calculate the area of the rectangle and display it. For the triangle, the program must prompt the user for the length of the triangles base and its height. Calculate the area of the triangle and display it. If the shape selected is trapezoid, the program must prompt the user for the height and the two base lengths. If sphere is selected, the program must prompt the user for the radius.
Make PI a named constant
Circle area = PI* r2
Rectangle area = length * width
Triangle area = base * height *0.5
Trapezoid area = height/2 (b1 + b2)
Sphere area = 4*PI*r2
If the user enters an invalid menu option, display a message telling the user what the valid choices are and exit the program. Do not allow the user to enter a negative number for any of the values used to calculate the areas.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
