Question

Using C++, Write a program that will provide the user a menu from which the user...

Using C++, Write a program that will provide the user a menu from which the user may select to calculate the area of one of four geometric shapes: a circle, a rectangle, a triangle, and a trapezoid. You should use the most appropriate SWITCH block for this program. The user will input all data needed to calculate the area. The program should output all data input by the user, the calculated area, and the geometric shape selected. Run this program using the following data: Run 1: select circle and use a radius of 2.3 Run 2: select rectangle and use length=5.5 and width=4.1 Run 3: Select triangle and use height=4 and base=1.8 Run 4: Select trapezoid and use height=6, a=11, and b=14

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;

int main()
{
int choice;
double radius,length,width,base,height,area,a,b;

//menu for the user to select a geometric shape
   cout<<"Choose one of the four geometric shapes\n1.Circle\t2.Rectangle\t3.Triangle\t4.Trapezoid\n";
   cin>>choice;

// switch loop to calculate area based on the choice of the user
   switch(choice)
   {
   case 1:
   cout<<"Enter the radius of Circle\n";
   cin>>radius;
   area=3.14*radius*radius;
   cout<<"Geometric Shape : Circle\n";
   cout<<"Radius : "<<radius<<endl;
   cout<<"Area : "<<area<<endl;
   break;
   case 2:
   cout<<"Enter the length and width of Rectangle\n";
   cin>>length>>width;
   area=length*width;
   cout<<"Geometric Shape : Rectangle\n";
   cout<<"Length : "<<length<<endl;
   cout<<"Width : "<<width<<endl;
   cout<<"Area : "<<area<<endl;
   break;
   case 3:
   cout<<"Enter the base and height of Triangle\n";
   cin>>base>>height;
   area=0.5*base*height;
   cout<<"Geometric Shape : Triangle\n";
   cout<<"Bse : "<<base<<endl;
   cout<<"Height : "<<height<<endl;
   cout<<"Area : "<<area<<endl;
   break;
   case 4:
   cout<<"Enter the height,a,b values of Trapezoid\n";
   cin>>height>>a>>b;
   area=0.5*height*(a+b);
   cout<<"Geometric Shape : Trapezoid\n";
   cout<<"Height : "<<height<<endl;
   cout<<"a : "<<a<<endl;
   cout<<"b : "<<b<<endl;
   cout<<"Area : "<<area<<endl;
   break;
   default:
   cout<<"Invalid choice\n";
   break;
   }
   return 0;
}

input Choose one of the four geometric shapes 4. Trapezoid 1.circle 2.Rectangle 3.Triangle 1 Enter the radius of Circle 2.3 Ginput Choose one of the four geometric shapes 4. Trapezoid 1.Circle 2.Rectangle 3.Triangle 2 Enter the length and width of Reinput v Choose one of the four geometric shapes 2. Rectangle 3. Trianqle 4.Trapezoid 1.Circle 3 Enter the base and height ofinput Choose one of the four geometric shapes 3. Triangle 1.Circle 4. Trapezoid 2. Rectangle 4 Enter the height,a,b values of

Add a comment
Know the answer?
Add Answer to:
Using C++, Write a program that will provide the user a menu from which the user...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Menu-driven programs will display the menu options to the user and then prompt them for a...

    Menu-driven programs will display the menu options to the user and then prompt them for a menu choice. This program will display the following menu in the following format: Calculator Options: 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) Once the user enters a choice for the menu, the program should use a...

  • Create a menu-driven program (using the switch) that finds and displays areas of 3 different objects....

    Create a menu-driven program (using the switch) that finds and displays areas of 3 different objects. The menu should have the following 4 choices: 1 -- rectangle 2 -- circle 3 -- triangle 4 -- quit If the user selects choice 1, the program should find the area of a rectangle. rectangle area = length * width If the user selects choice 2, the program should find the area of a circle. circle area = PI * radius * radius...

  • Geometric calclator use python to do this program. Write a program that displays the following menu:...

    Geometric calclator use python to do this program. Write a program that displays the following menu: 1. Calculate the area of circle 2. calculate the area of rectangle 3. calculate the area of triangle 4. Quit Enter your choice (1-4). if the user enters 1, your program should ask for the radius of the circle and then display its area. Use the formula to calculate the circle's area: Area = pi*r^2 Use 3.14149 for Pi and the radius of the...

  • Q2: Write a menu-driven C program using switch-case to calculate the following: 1. Area of circle...

    Q2: Write a menu-driven C program using switch-case to calculate the following: 1. Area of circle 2. Area of square 3. Area of rectangle The program should use the following functions properly: void displayMenu() //a function that will display the menu options to the user int getChoice() //a function that will input the user choice and returns it float calculate(int choice) //a function that reads the required inputs based on the user choice, and returns the area of the shape...

  • (PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code Geometry Calculator...

    (PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code 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. If the user enters 2, the program should ask for the length and width of...

  • Java only please Write a program that displays the following menu: Geometry Calculator 1.       Calculate the...

    Java only please Write a program that displays the following menu: Geometry Calculator 1.       Calculate the Area of a Circle 2.       Calculate the Area of a Triangle 3.     Calculate the Area of a Rectangle 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 formula:      area = ∏r2    Use 3.14159 for ∏. If the user enters 2 the program should ask for...

  • IN C++ You are to write a program which will get the following variables from the...

    IN C++ You are to write a program which will get the following variables from the user. Length, Width, Height, Radius, Base. You should also have variables for Pi as 3.14 and choice1 and choice2. Your program will first ask the following: Press 1 to calculate Area Press 2 to calculate Perimeter The choice will be saved in choice1. You should then ask another choice: Press 1 for Rectangle Press 2 for Triangle Press 3 for Circle You have all...

  • Write a Java program that prompts user to select one of the five shapes(Rectangle, Square, Triangle,...

    Write a Java program that prompts user to select one of the five shapes(Rectangle, Square, Triangle, Circle, and Parallelogram), then calculate area of the shape,must have input validation and uses more of java library like math class, wrapper class, string methods, use formatted output with the printf method. Finally, create a pseudo-code statement and flowchart

  • Write a C program that does the following: • Displays a menu (similar to what you...

    Write a C program that does the following: • Displays a menu (similar to what you see in a Bank ATM machine) that prompts the user to enter a single character S or D or Q and then prints a shape of Square, Diamond (with selected height and selected symbol), or Quits if user entered Q. Apart from these 2 other shapes, add a new shape of your choice for any related character. • Program then prompts the user to...

  • Write a program in Java that can calculate and output the area of three different shapes;...

    Write a program in Java that can calculate and output the area of three different shapes; a rectangle, a triangle and a circle. Let the user choose which shape they want by typing the words “rectangle”, “triangle” or “circle” (you may use integers, strings or chars to indicate which shape the user prefers to calculate the area of). Then, have the user enter the values of the dimension(s) appropriate for each shape in the form of doubles.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT