Ch 4 Program 2 – GeometryCalculator
Please adhere to the Standards for Programming Assignments and the C++ Coding Guideline.
Submit the following:
ï‚· List of source code with comments to document
ï‚· Test output listed as comments at the end of your program
GeometryCalculator.cpp (15 pts)
Write a program that displays the following menu:
1. Calculate the area of a circle
2. Calculate the area of a rectangle
3. Calculate the area of a triangle
4. Quit
Prompt the user to enter a menu choice.
Then based on the user’s choice use a switch statement to do the following:
ï‚· If the user enters 1, then you should prompt for the radius of the circle and display its area. Use
3.14159 for PI.
ï‚· If the user enters 2, then prompt for the length and width of the rectangle, and then display the
rectangle’s area.
ï‚· If the user enters 3, then prompt for the base and height of the triangle, and then display its
area.
ï‚· If the user enters 4, the program should end.
Input validation:
Display an error message if the user enters a menu number outside the range of 1 through 4 and end
the program.
Only accept positive values for the circle’s radius, the rectangle’s length or width, or the triangle’s base
or height. Display an error message and end the program.
Test data: Your included output must show your program running with the following sequence.
Menu choice 1. Radius = 3.7
Menu choice 2. length = 5.5, width = 3.
Menu choice 4. Should quit program.
Menu choice 9. Should generate error message.
Menu choice 3. base = -6.2, height = 4. Should generate error message.
Example output:
***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): 1
Enter the circle’s radius: 3.7
The area is 43.0084
Thanks for using the Geometry Calculator!
Press any key to continue . . .CSC100AA and CIS162AA Chapter 4 : Making Decisions
Ch4 Program 2 – GeometryCalculator.doc pbaker page 1 of 2