Question

C++ programming For this assignment, write a program that will act as a geometry calculator. The...

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 triangle’s 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 triangle’s 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go this code and let me know if u need any changes in this.Thank You
_________________

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

// Function Declarations
int menu();
int getPositiveInt( string prompt );
void displayArea( string label, double area ) ;
   int main()
   {
/* This loop continues to execute until
   * the user enters a valid choice
   */
int choice;
while(true)
{
   //calling the function
choice=menu();
       switch(choice)
       {
           case 1:{
               int radius;
               string prompt="What is the radius of the circle? ";
               //calling the function
               radius=getPositiveInt(prompt);
               double area=3.14159*radius*radius;
               string label="The area of the circle is ";
               //calling the function
               displayArea(label,area);
               continue;
           }
           case 2:{
                   int base,height;
               string prompt="What is the length of the base of the triangle? ";
               //calling the function
               base=getPositiveInt(prompt);
               prompt="What is the height/altitude of the triangle? ";
               //calling the function
               height=getPositiveInt(prompt);
               double area=0.5*base*height;
               string label="Area of the triangle is ";
               //calling the function
               displayArea(label,area);
               continue;
           }
           case 3:{
               cout<<"Goodbye!"<<endl;
               break;
           }
          
          
           }
           break;   
       }
      
       return 0;  
   }

//This function will dislpay the menu
int menu()
{
   int choice;
  
   /* This while loop continues to execute
* until the user enters a valid number
*/
   while(true)
   {
   cout<<"\nGeometry Calculator"<<endl;
cout<<"\n1. Calculate the area of a circle"<<endl;
   cout<<"2. Calculate the area of a triangle"<<endl;
   cout<<"3. Quit"<<endl;
   cout<<"\nEnter your choice(1-3):";
   cin>>choice;
   if(choice<1 || choice>3)
   {
       cout<<"*** ERROR: "<<choice<<" is an invalid selection ***"<<endl;
   }
   else
   {
       return choice;
   }
      
   }
  
}
int getPositiveInt( string prompt )
{
   int radius;
   while(true)
   {
       cout<<prompt;
       cin>>radius;
       if(radius<0)
       {
       cout<<"** Invalid.Must be Positive **"<<endl;
       continue;  
       }
       else
       break;
      
      
   }
}
void displayArea( string label, double area )
{
  
   //setting the precision to two decimal places
   std::cout << std::setprecision(3) << std::fixed;
     
   cout<<label<<area<<endl;
}

_______________________

Output:

_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
C++ programming For this assignment, write a program that will act as a geometry calculator. The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code Geometry Calculator...

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

  • Java only please Write a program that displays the following menu: Geometry Calculator 1.       Calculate the...

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

  • Menu-driven programs will display the menu options to the user and then prompt them for a...

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

  • Geometric calclator use python to do this program. Write a program that displays the following menu:...

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

  • Create a menu-driven program (using the switch) that finds and displays areas of 3 different objects....

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

  • Design program so that it correctly meets the program specifications given below.   Specifications: Create a menu-driven...

    Design program so that it correctly meets the program specifications given below.   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 If the user selects choice 1, the program should find the area of a square. If the user selects choice 2, the program should find the area of a circle. If the user...

  • programming language: C++ *Include Line Documenatations* Overview For this assignment, write a program that will simulate...

    programming language: C++ *Include Line Documenatations* Overview For this assignment, write a program that will simulate a game of Roulette. Roulette is a casino game of chance where a player may choose to place bets on either a single number, the colors red or black, or whether a number is even or odd. (Note: bets may also be placed on a range of numbers, but we will not cover that situation in this program.) A winning number and color is...

  • Problem: Given information about a circle, rectangle and a triangle, calculate the area of the shape...

    Problem: Given information about a circle, rectangle and a triangle, calculate the area of the shape from the information supplied. Write pseudocode to solve this problem and write a Python program that asks the user to input the required information for a shape and then calculates the area of the shape. 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...

  • Write a C program Design a program that uses an array to store 10 randomly generated...

    Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...

  • CE – Return and Overload in C++ You are going to create a rudimentary calculator. The...

    CE – Return and Overload in C++ You are going to create a rudimentary calculator. The program should call a function to display a menu of three options: 1 – Integer Math 2 – Double Math 3 – Exit Program The program must test that the user enters in a valid menu option. If they do not, the program must display an error message and allow the user to reenter the selection. Once valid, the function must return the option...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT