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