Question: 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

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 (PI = 3.14159)
  • If the user selects choice 3, the program should find the area of a triangle.
    • triangle area = base * height * 0.5
  • If the user selects choice 4, the program should quit without doing anything.

If the user selects anything else (i.e., an invalid choice) an appropriate error message should be printed.

HINTS:

// 1. DEFINE THE NAMED CONSTANT PI AND SET ITS VALUE TO 3.14159 // 2. DECLARE ALL NEEDED VARIABLES and GIVE EACH ONE A DESCRIPTIVE NAME // AND AN APPROPRIATE DATA TYPE. // 3. USE AN IF/ELSE IF STATEMENT TO OBTAIN ANY NEEDED INPUT INFORMATION // AND COMPUTE AND DISPLAY THE AREA FOR EACH VALID MENU CHOICE. // 4. IF AN INVALID MENU CHOICE WAS ENTERED, AN ERROR MESSAGE SHOULD // BE DISPLAYED.

Sample Run

Program to calculate areas of objects

1 -- rectangle

2 -- circle

3 -- triangle

4 -- quit

2

Radius of the circle: 3.0

Area = 28.2743

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!