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...
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...
C++ Write a program that displays the follow menu: Geometry Calculator    1. Calculate the Area...
C++ Write a program that displays the follow menu: 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 then display it's area using the following formula: area = PIr2 Use 3,14159 for PI and the radius of the circle for r. If the...
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 C++ program to allow the user to: 1. Create two classes. Employee and Departments....
Write a C++ program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to do the following: 1....
Isolating bits and bytes Task: Create a program that manages an IP address. Allow the user...
Isolating bits and bytes Task: Create a program that manages an IP address. Allow the user to enter the IP address as four 8 bit unsigned integer values (just use 4 sequential CIN statements). The program should output the IP address upon the users request as any of the following. As a single 32 bit unsigned integer value, or as four 8 bit unsigned integer values, or as 32 individual bit values which can be requested as a single bit...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT