Question: #include #include using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159; //repeat until user wants to quits while(true) { //menu

#include #include using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159; //repeat until user wants to quits while(true) { //menu cout<>choice; cout<>radius; //calculating area area=PI*radius*radius; cout<>base; cout<<"What is the height/altitude of the triangle ? "; cin>>height; //calculating area area=0.5*base*height; cout< 

Overview

For this assignment, re-write the program above so that it uses functions rather than having all of the code in int main().

Basic Program Logic

As with the program above, 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 the program above. 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 the program above. 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.

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 the program above 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). 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 entered 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

Each function must have a documentation box explaining:

/*************************************************************** 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 ***************************************************************/
  1. 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

    • 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.

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!