Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 has been made, if the user did not choose the quit option, the program should enter a loop that will continue until the user wants to quit.

If the user chose the circle option (1), the program should prompt them to enter the radius of a circle. That value should then be used to calculate the area of a circle using the formula:

 Area of a Circle = r2

where r is the radius of the circle. Use the value 3.14159 as the value for pi.

If the user chose the triangle option (2), the program should prompt them to enter the length of the triangles base and and its height. Those values should then be used to calculate the area of a triangle using the formula:

Area of a Triangle = 1/2 * base * height

If the user entered an invalid option (something other than 1, 2, or 3), the program should display an error message about an invalid choice being made.

At the end of the loop, the menu should be displayed to the user again and their new choice should be read.

Program Requirements

  1. All of the calculated areas should be displayed with exactly 3 digits after the decimal point.

  2. The numeric values read in from the user should all be data type integer. The calculated areas should all be data type float or double. Make sure to use meaningful variable names.

  3. Make sure and test your program with values that you have calculated.

  4. Hand in a copy of your source code using Blackboard.

Sample Output

Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): 7 *** ERROR: 7 is an invalid selection *** Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): 1 What is the radius of the circle? 8 The area of the circle is 201.062 Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): 2 What is the length of the base of the triangle? 4 What is the height/altitude of the triangle? 3 The area of the triangle is 6.000 Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): 3 Goodbye!

Basic Program Logic As with program 5, this version of the geometry calculator program will start by displaying a menu to the user and getting their choice as an integer. However, this will be done by calling the menu() function that is described below rather than having the cout/cin in main(). After the user's choice has been made, if the user did not choose the quit option, the program should enter a loop that will continue until the user wants to quit. If the user chose the circle option (1), call the getPositiveInt() function that is described below to prompt the user to enter the radius of a circle. The value that is returned from getPositiveInt() should then be used to calculate the area of a circle using the formula from program 5. After the area has been calculated, call the displayArea() function to display the calculated area of the triangle. If the user chose the triangle option (2), call the getPositiveInt() function to prompt the user to enter the length of the triangles base and then call the getPositiveInt() function a second time to prompt the user to enter the height of the triangle. The two values that are returned from the two getPositiveInt() calls should then be used to calculate the area of a triangle using the formula from program 5. After the area has been calculated, call the displayArea() function to display the calculated area of the triangle. At the end of the loop, call the menu() function (again) to display the menu to the user and get their new choice. Note 1: the check for an invalid menu option has been removed from main() in this program because it will now be handled in the menu() function. Note 2: If the extra credit portion of program 5 was completed, make sure that the code in program 6 is modified to call the getPositiveInt() function to get the lengths of the semi-major and semi-minor axis and to call the displayArea() function to display the calculated area of the ellipse. The Functions Write and use the following 3 functions in the program. int menu() This function will display a menu and get a VALID choice from the user. It takes no arguments. It returns an integer: the valid menu choice. The function should display the menu from program 5 to the user and then get the user's choice. The user's choice should then be checked to make sure it's valid (1, 2, 3 --OR-- 1, 2, 3, 4 if you did the extra credit portion of program 5). As long as the user has entered an invalid choice, an error message should be displayed and the user should be given a chance to re-enter their choice. Once the user has entered a valid choice, it should be returned. int getPositiveInt( string prompt ) This function will get a positive integer from the user. It takes one argument: a string that contains the prompt that should be displayed to the user. It returns an integer: the positive value that is enterd by the user. The function should simply display the string argument (prompt) to the user and then get the user's integer value. The user's value should then be checked to make sure it's positive. As long as the user has entered a negative value or 0, an error message should be displayed and the user should be given a chance to re-enter their value. Once the user has entered a positive integer value, it should be returned. void displayArea( string label, double area ) This function will display a calculated area. It takes two arguments: a string that contains the label that should be displayed with the area and a double that contains the area to be displayed. It returns nothing. The function should simply display the string (label) and double (area) arguments to the user in a formatted manner. The area should be displayed with exactly 3 digits after the decimal point. Program Requirement As with the previous assignments and the assignments until the end of the semester, complete program documentation is required. For this assignment, that means that line documentation AND function documentation boxes are needed. In regards to line documentation, there is no need to document every single line, but logical "chunks" of code should be preceded by a line or two that describe what the "chunk" of code does. Make sure that main() and any function that you write contains line documentation Each function must have a documentation box explaining: its name its use or function: that is, what does it do? What service does it provide to the code that calls it? a list of its arguments briefly describing the meaning and use of each the value returned (if any) or none notes on any unusual features, assumptions, techniques, etc. /*************************************************************** Function: int menu() Use: This function displays a menu to the user and gets their choice. Arguments: None Returns: integer - the user's choice from the menu Note: The user's choice is checked to make sure that it is valid ***************************************************************/ See the documentation standards on the course webpage for more examples or if further clarification is needed. Your program will not get full credit (even if it works correctly) if these standards are not followed Make sure to test your program with values that you have calculated.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

What are five reasons that customers defect to competitors?

Answered: 1 week ago