Write a menu program that will print various formulas and do calculations. For e
ID: 3643936 • Letter: W
Question
Write a menu program that will print various formulas and do calculations. For each menu choice, display the formula and prompt for the necessary values. Then calculate and print the area and the perimeter.Your program must have 5 functions as follow:
1) int getMenuChoice( ); // display the menu, get and return the choice.
2) void Circle( double *radius, double *area, double *perimeter ); // display the formulas, get the radius, calculate the area and the perimeter, function should return the values through the output perimeters.
3) void displayCircle( double radius, double area, double perimeter ); // display the all the values in a tabular format.
4) void Rectangle( double *length, double *width, double *area, double *perimeter ); // display the formulas, get the length and the width, calculate the area and the perimeter, function should return the values through the output perimeters.
5) void displayRectangle( double length, double width, double area, double perimeter ); // display the all the values in a tabular format.
Explanation / Answer
#include #include const int pi=3.14; int getMenuChoice( ) { int ch; printf(" MENU"); printf("1. Circle"); printf("2. Display Circle"); printf("3. Rectangle"); printf("4. Display Rectangle"); scanf("%d",&ch); return ch; } void Circle( double *radius, double *area, double *perimeter ) { double r; printf(" The Area of Circle is: pi*radius*radius"); printf(" The Perimeter of Cirle is: 2*pi*radius"); printf(" Enter the radius:"); scanf("%lf",&r); *radius=r; *perimeter=2*pi*r; *area=pi*r*r; } void displayCircle( double radius, double area, double perimeter ) { printf(" The Result is:"); printf(" Radius Area Perimeter"); printf("%lf %lf %lf",radius,area,perimeter); } void Rectangle( double *length, double *width, double *area, double *perimeter ) { double l,w; printf(" The Area of Rectangle is: length*width"); printf(" The Perimeter of Rectangle is: 2*(length+width)"); printf(" Enter the Length and witdh:"); scanf("%lf %lf",&l,&w); *length=l; *width=w; *area=l*w; *perimeter=2*(l+w); } void displayRectangle( double length, double width, double area, double perimeter ) { printf(" The Result is:"); printf(" Length Width Area Perimeter"); printf("%lf %lf %lf &lf",length,width,area,perimeter); } void main() { double r,l,w,acircle,pcircle,arectangle,prectangle; int ch; char chh; ch=getMenuChoice(); do { switch(ch) { case 1:circle(&r,âle,&pcircle); break; case 2:displayCircle(r,acircle,pcircle); break; case 3:rectangle(&l,&w,&arectangle,&prectangle); break; case 4:displayRectangle(l,w,arectangle,prectangle); break; default:printf("Wrong Choice...Please Try again!!!"); break; } printf(" Do you want to try again (y or Y for Yes n or N for No??"); scanf("%c",&chh); }while(chh=='y'||chh=='Y'); getch(); }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.