Specifications: Create a menu-driven program that finds and displays areas of 3 different objects. The menu should have the following 4 choices: 1 -- square 2 -- circle 3 -- right triangle 4 -- quit
|
Sample Run Program to calculate areas of objects 1 -- square 2 -- circle 3 -- right triangle 4 -- quit 2 Radius of the circle: 3.0 Area = 28.2743 |
2: Once you have your program working, run it 4 times, each time testing a different valid menu choice. Then run it a fifth time using an invalid menu choice (such as 0 or 5). Make sure your program works correctly for all cases and take copy of it.
The following is the menu-driven program implemented in python
Source code:
# Python Program to calculate the area of different shapes
import math
# Print Menu
print("Select anyone from the below choices")
print("1 -- square")
print("2 -- circle")
print("3 -- right triangle")
print("4 -- quit")
# Main function
def main():
# Take input of the choice
choice = int(input("Enter any choice from the above available choices: "))
# Square
if choice == 1:
print("You have selected square option")
side = float(input("Enter the side of the square: "))
area = side ** 2
print("The area of the square is: {}".format(area))
# Circle
elif choice == 2:
print("You have selected circle option")
radius = float(input("Enter the radius of the circle: "))
area = math.pi * (radius ** 2)
print("The area of the circle is: {}".format(area))
# Right triangle
elif choice == 3:
print("You have selected right triangle option")
a, b, c = list(map(float, input("Enter the base, height, hypotenuse of right triangle separated by a space: ").split()))
area = 0.5 * a * b
print("The area of the right triangle is: {}".format(area))
# Quit
elif choice == 4:
print("You have selected quit option")
print("Program has been terminated")
return
# Invalid choice
else:
print("Invalid choice has been selected. Please select choices from 1-4 as shown above")
if __name__ == "__main__":
main()
Please refer to the following code screenshots for the
indentation:
Execution of the above code with different choices is shown below:
Choice - 1
Choice - 2
Choice - 3
Choice - 4
Invalid choice
Design program so that it correctly meets the program specifications given below. Specifications: Create a menu-driven...
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...
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...
C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...
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...
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...
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...
(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...
Please use C++ and output have to look like that Create a menu driven C++ program with functions. There must be four functions, calculating the size of area of circle, rectangle, triangle, and parallelogram. You are required to create those four functions and invoke them from the main program in order to reccive any credit. Please Submit: . A flowchart of your program with equations and expected results. 4 points) 2. Printout of your C++program with a heading comment, also...
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...