Question

In: Computer Science

Create a menu-based program that will allow the user to calculate the area for a few...

  • Create a menu-based program that will allow the user to calculate the area for a few different shapes: square, rectangle, parallelogram, and circle.
  • Refer to the Sample Output in this document to see what menu options you should use.
  • Create PI as a global constant variable.
  • Main Function
    • use do-while to repeat program until user chooses option 5
    • call the displayMenu function
    • get user choice & validate with while loop
    • depending on user’s choice, get the data required to calculate the area of the shape from the user and then call the appropriate function to calculate the area.

  • Write five programmer-defined functions.
    • displayMenu – should print out the menu options
    • areaSquare() – should accept the height of the square from the main function, calculate the area, and then print the area of the square.
    • areaRectangle() – should accept the height & width of the rectangle from the main function, calculate the area, and then print the area of the rectangle.
    • areaParallelogram() – should accept the base & height of the parallelogram from the main function, calculate the area, and then print the area of the parallelogram.
areaCircle() – should accept the radius of the circle from the main function, calculate the area, and then print the area of the circle.

Solutions

Expert Solution

Code:

#include<iostream>
#include<cmath>
using namespace std;
#define PI M_PI
void displayMenu()
{/*printing the menu*/
   cout<<"Menu"<<endl;
   cout<<"1.Area of Square"<<endl;
   cout<<"2.Area of Rectangle"<<endl;
   cout<<"3.Area of Parllelogram"<<endl;
   cout<<"4.Area of Circle"<<endl;
   cout<<"5.Exit"<<endl;
}
double areaSquare(double height)
{/*Returning the area of the square*/
   return(height*height);
}
double areaRectangle(double height,double width)
{/*Returning the area of the rectangle*/
   return(height*width);
}
double areaParllelogram(double base,double height)
{/*Returning the area of the parllelogram*/
   return(base*height);
}
double areaCircle(double radius)
{/*Returning the area of the circle*/
   return(PI*radius*radius);
}
int main()
{
   int choice;
   double height,width,base,radius;/*Declaring variables*/
   do
   {/*This loop iterates untill choice is 5*/
       displayMenu();/*Calling display menu*/
       cout<<"Enter your choice:";
       cin>>choice;/*Reading choice form the user*/
       switch(choice)
       {
           case 1:/*If choice is 1*/
               cout<<"Enter the height of the square:";
               cin>>height;/*Reading height of the square*/
               cout<<"Area of the square is :"<<areaSquare(height)<<endl;
               break;/*Printing the area of square by calling areaSquare function*/
           case 2:/*If choice is 2*/
               cout<<"Enter the height of the rectangle:";
               cin>>height;
               cout<<"Enter the width of the rectangle:";
               cin>>width;/*Reading height and width*/
               cout<<"Area of the Rectangle is :"<<areaRectangle(height,width)<<endl;
               break;/*Printing the result*/
           case 3:/*If choice is 3*/
               cout<<"Enter the base of the parllelogram:";
               cin>>base;
               cout<<"Enter the height of the parllelogram:";
               cin>>height;/*Reading height and base */
               cout<<"Area of the Parllelogram is :"<<areaParllelogram(base,height)<<endl;
               break;/*Printing the result*/
           case 4:/*If choice is 4*/
               cout<<"Enter the radius of the circle:";
               cin>>radius;/*Reading radius form the user*/
               cout<<"Area of the circle:"<<areaCircle(radius)<<endl;
               break;/*printing the result*/
           case 5:/*If choice is 5*/
               break;
           default:
               cout<<"Invalid choice"<<endl;
               break;      
       }  
   }
   while(choice!=5);  
}

Output:

Indentation:


Related Solutions

We need to create basic program that will simply display a menu and allow the user...
We need to create basic program that will simply display a menu and allow the user to select one of the choices. The menu should be displayed such that each option will be numbered, as well as have one capital letter so as to indicate that either the number or the designated letter can be entered to make their choice. Once the choice is made, the sub-menu for that selection should be displayed. Colors with an odd number of letters...
create a program that will allow the user to enter a start value from 1 to...
create a program that will allow the user to enter a start value from 1 to 5, a stop value from 10 to 12 and a multiplier from 1 to 4. the program must display a multiplication table from the values entered. for example if the user enters: start 2, stop 10 and multiplier 3, the table should appear as follows: 3*2=6 3*3=9 3*4=12 . . . 3*10=30
rite a program that will calculate the perimeter and area of a rectangle. Prompt the user...
rite a program that will calculate the perimeter and area of a rectangle. Prompt the user to input the length and width. Calculate the area as length * width. Calculate the perimeter as 2* length + 2* width. Display the area and perimeter. Please use a proper heading in a comment block (name, date, description of the program). Please use comments in your code. Run your program twice using different input. Copy the output and place it at the bottom...
create a program that asks user math questions and keeps track of answers... Python Allow the...
create a program that asks user math questions and keeps track of answers... Python Allow the user to decide whether or not to keep playing after each math challenge. Ensure the user’s answer to each math problem is greater than or equal to zero. Keep track of how many math problems have been asked and how many have been answered correctly. When finished, inform the user how they did by displaying the total number of math problems, the number they...
Write a GUI based Python program that will allow the user to perform (i) generate RSA...
Write a GUI based Python program that will allow the user to perform (i) generate RSA keys, (ii) encrypt a given message and (iii) decrypt the message without using any cryptographic library. Your program will generate the values of p unless the user provides them manually. Then the program will generate the keys (private and public). Then the program will allow the user to enter his/her message to be encrypted. Finally, the program will perform the decryption operation as well....
User the Scanner class for your input Write a java program to calculate the area of...
User the Scanner class for your input Write a java program to calculate the area of a rectangle. Rectangle Area is calculated by multiplying the length by the width   display the output as follow: Length =   Width = Area = Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
Write a python program that will allow a user to draw by inputting commands. The program...
Write a python program that will allow a user to draw by inputting commands. The program will load all of the commands first (until it reaches command "exit" or "done"), and then create the drawing. Must include the following: change attributes: color [red | green | blue] width [value] heading [value] position [xval] [yval] drawing: draw_axes draw_tri [x1] [y1] [x2] [y2] [x3] [y3 draw_rect [x] [y] [b] [h] draw_poly [x] [y] [n] [s] draw_path [path] random random [color | width...
Write a C/C++ program that simulate a menu based binary numbercalculator. This calculate shall have...
Write a C/C++ program that simulate a menu based binary number calculator. This calculate shall have the following three functionalities:Covert a binary string to corresponding positive integersConvert a positive integer to its binary representationAdd two binary numbers, both numbers are represented as a string of 0s and 1sTo reduce student work load, a start file CSCIProjOneHandout.cpp is given. In this file, the structure of the program has been established. The students only need to implement the following three functions:int binary_to_decimal(string...
print a menu so that the user can then order from that menu. The user will...
print a menu so that the user can then order from that menu. The user will enter each item they want until they are done with the order. At the end you will print the items the user ordered with their price and the total. Note: You will be storing your menu items (pizza, burger, hotdog, salad) and your prices (10, 7, 4, 8) in separate lists. Menu 0) pizza $10 1) burger $7 2) hotdog $4 3) salad $8...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main()...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main() function to coordinate the execution of the program. We will need methods: Method for Depositing values into the account. What type of method will it be? Method for Withdrawing values from the account. What type of method will it be? Method to output the balance of the account. What type of method will it be? Method that will output all deposits made to the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT