Write a program that displays the following menu: Geometry Calculator ----------
ID: 3696070 • Letter: W
Question
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. Calculate the Area of a Trapezoid 5. Quit Enter your choice (1-5): 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:=:pi r^2 Use 3.14159 for 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:=:lw 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:=:rac{1}{2}bh If the user enters 4: The program should ask for the length of the Trapezoid's top base, bottom base, and its height. Use the following formula: area:=:rac{b1+b2}{2}h If the user enters 5, the program should end. Input Validation Display an error message if the user enters a number outside the range of 1 through 5 when selecting an item from the menu. Do not accept negative values for the circle’s radius, the rectangle’s length or width, the triangle’s base or height, or the trapezoids base1, base 2, or height.
Explanation / Answer
Can help you with this:
include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const double PI = 3.14159;
double radius=0.0;
double area=0.0;
double length=0.0;
double width=0.0;
double base=0.0;
double base1=0.0;
double base2=0.0;
double height=0.0;
int choice=0;
cout << "Geometry Calculator ";
cout << " ";
cout << "1. Calculate the area of a Circle ";
cout << "2. Calculate the area of a Rectangle ";
cout << "3. Calculate the area of a Triangle ";
cout << "4. Calculate the area of a Trapezoid ";
cout << "5. Exit ";
cout << "Enter your choice (1-5): ";
cin >> choice;
if (choice>=1 && choice<=5)
{
switch (choice)
{
case 1:
cout << " ";
cout << "Enter the circle's radius: ";
cin >> radius;
if (radius>0)
{
area = (PI * radius * radius);
//cout << fixed << setprecision(4);
cout << "The area is " << area;
break;
case 2:
cout << " ";
cout << "Enter the rectangle's length: ";
cin >> length;
cout << "Enter the rectangle's width: ";
cin >> width;
if (length>0 && width>0)
{
area = length * width;
cout << "The area is " << area;
break;
case 3:
cout << "Enter the length of the base: ";
cin >> base;
cout << "Enter the triangle's height: ";
cin >> height;
if (base>0 && height>0)
{
area = (base * height)/2;
cout << "The area is " << area;
break;
case 4:
cout << "Enter the Trapezoid's height";
cin >> height;
cout << "Enter the Trapezoid's base 1";
cin >> base1;
cout << "Enter the Trapezoid'd base 2";
cin >> base2;
if (base1>0 && base2>0 && height>0)
{
area = (height * (base1 + base2))/2;
cout << "The area is " << area;
break;
case 5:
cout << "Program Ending.";
break;
}
}
else
{
cout << "The valid choices are 1 through 5.";
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.