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

//Program for Calculate area of diffrent  type of Shapes

#include<stdio.h>
#include<conio.h>
#define pi 3.14
void areaSquare();
void areaRectangle();
void areaParallelogram();
void areaCircle();
void displayMenu();
void main()
{
clrscr();
displayMenu();
getch();
}
void displayMenu()
{
int key;
do
{
printf("Enter your choice to calculate area of which shape:\n1:Area of Square\n2:Area of Rectangle\n3:Area of Parallelogram\n4:Area of Circle\n5:exit")
;
scanf("%d",&key);
switch(key)
{
case 1: areaSquare();
   break;
case 2: areaRectangle();
   break;
case 3: areaParallelogram();
   break;
case 4: areaCircle();
   break;
case 5: exit();
default: printf("Enter Correct choice\n");
}
}while(1);
}
void areaSquare()
{
int a;
float area;
printf("Enter side to calculate Area of Square\n");
scanf("%d",&a);
area=a*a;
printf("\nArea of Square is %.2f",area);
return;
}
void areaRectangle()
{
int a,b;
float area;
printf("Enter length, width to calculate Area of Rectangle\n");
scanf("%d%d",&a,&b);
area=a*b;
printf("\nArea of Rectangle is %.2f",area);
return;
}
void areaParallelogram()
{
int a,b;
float area;
printf("Enter base, height to calculate Area of Parallelogram\n");
scanf("%d%d",&a,&b);
area = a*b;
printf("\nArea of Parallelogram is %.2f",area);
return;
}
void areaCircle()
{
int a;
float area;
printf("Enter radius to calculate Area of Circle\n");
scanf("%d",&a);
area = pi*a*a;
printf("\nArea of Circle is %f",area);
return;
}


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