Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Chapter 4 : Programming Project 2 Unlimited tries Write a program that displays the following menu. The symbols show where newline characters (
Chapter : Programming Project
Unlimited tries
Write a program that displays the following menu. The
symbols show where newline characters
should be displayed:
Geometry Calculator
Calculate the Area of a Circle
Calculate the Area of a Rectangle
Calculate the Area of a Triangle
Quit
Enter your choice :
If the user enters : The program should print the following string as a prompt:
Enter the circle's radius:
The program should then read the radius of the circle as input and then calculate the circle's area using the following formula:
Area pi r
In your calculation, use for pi and the radius of the circle for r
The program should then print the string
The area is followed by the area, followed by a newline.
If the user enters : The program should print the following string as a prompt:
Enter the rectangle's length:
The program should read the length as input and then print the following string as a prompt:
"Enter the rectangle's width:
The program should read the width as input and then calculate the rectangle's area using the following formula:
Area length times width
The program should then print the string
The area is followed by the area, followed by a newline.
If the user enters : The program should print the following string as a prompt:
"Enter the length of the base:
The program should read the base as input and then print the following string as a prompt:
"Enter the triangle's height:
The program should read the height as input and then calculate the triangle's area using the following formula:
Area base times height times
The program should then print the string
The area is followed by the area, followed by a newline.
If the user enters : The program should print the string "Program ending.
and then end.
Input Validation:
The only valid menu choices the user can make are or If the user makes a menu choice other than one of these numbers, the program should print the following strings and then end:
"The valid choices are through Run the
"program again and select one of those.
If the user enters a negative number for the circle's radius, print the following string, and then end:
The radius can not be less than zero.
If the user enters a negative number for the rectangle's length OR width, print the following string, and then end:
Only enter positive values for length and width.
If the user enters a negative number for the triangle's base OR height, print the following string, and then end:
Only enter positive values for base and height.
Sample Run
Geometry Calculator
Calculate the area of a Circle
Calculate the area of a Rectangle
Calculate the area of a Triangle
Quit
Enter your choice :
Enter the circle's radius:
The area is
Sample Run
Geometry Calculator
Calculate the area of a Circle
Calculate the area of a Rectangle
Calculate the area of a Triangle
Quit
Enter your choice :
Enter the rectangle's length:
Enter the rectangle's width:
The area is
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started