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

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...
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...
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user...
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user to choose options. The program must have a file dialogue box for text file. Output should be based on user choices. Read in a file Print the file to the console Encrypt the file and write it to the console Write out the encrypted file to a text file Clear the data in memory Read in an encrypted file Decrypt the file Write out...
PYTHON In this lab we will design a menu-based program. The program will allow users to...
PYTHON In this lab we will design a menu-based program. The program will allow users to decide if they want to convert a binary number to base 10 (decimal) or convert a decimal number to base 2 (binary). It should have four functions menu(), reverse(), base2(), and base10(). Each will be outlined in detail below. A rubric will be included at the bottom of this document. Menu() The goal of menu() is to be the function that orchestrates the flow...
Create a program that will ask the user to choose their order from a simple menu....
Create a program that will ask the user to choose their order from a simple menu. Customers first choose from three types of dishes: Sandwiches/wraps, Rice Meals, or Noodles. They can type in 1, 2, or 3 to select the type then, they choose a specific dish as shown below. Confirm their order by displaying it on the screen after they make their selection. 1. Sandwiches/wraps Hamburger Chicken shawarma 2. Rice meals Arroz con pollo Chana masala 3. Noodles Chow...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Important! Consider which control structures will work best for which aspect of the assignment. For example, which would be the best to use for a menu?...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Your code must contain at least one of all of the following control types: nested for() loops a while() or a do-while() loop a switch() statement...
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
Create design document for a program that will allow the user: Convert a number to binary....
Create design document for a program that will allow the user: Convert a number to binary. Convert from binary to number. Display the hexadecimal representation of a binary number. Given an hexadecimal display its binary representation. Convert a number to IEEE single precision and vice versa. More to come. PLEASE ADD PSEUDOCODE AND USE C PROGRAMMING USE FUNCTIONS IF POSSIBLE
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT