Write the C++ code of following functions: compute_Circle that returns area and
ID: 3739818 • Letter: W
Question
Write the C++ code of following functions:
compute_Circle that returns area and circumference of a circle with given radius r.
compute_Rectangle that returns area and perimeter of a rectangle with given length l and width w.
compute_Triangle that returns the area and the perimeter of a triangle with given sides a, b, c.
compute_Sphere that returns volume and surface area of a sphere with given radius r.
compute_Cylinder that returns volume and surface area of a cylinder with given radius r and height h.
Design a menu function that will take a number from the user as input and then perform specific operation based on input value. All cin and cout should only be done in the menu function.
On ‘1’ print area and circumference of circle.
On ‘2’ print area and Perimeter of a rectangle.
On ‘3’ print area and the perimeter of a triangle.
On ‘4’ print volume and surface area of a sphere
On ‘5’ print volume and surface area of a cylinder
On ‘6’ Exit Program.
YOU CANNOT USE ANY break, continue or goto statement IN THIS
Explanation / Answer
#include<iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;
void compute_Circle(float r,float &p,float &q)
{
p=3.14*r*r;
q=2*3.14*r;
}
void compute_Rectangle(float l,float w,float &p,float &q)
{
p=l*w;
q=2*(l+w);
}
void compute_Triangle(float a,float b,float c,float &p,float &q)
{
p=a+b+c;
q=sqrt(p/2*(p/2-a)*(p/2-b)*(p/2-c));
}
void compute_Sphere(float r,float &p,float &q)
{
p=(4*3.14*r*r*r)/3;
q=4*3.14*r*r;
}
void compute_Cylinder(float r,float h,float &p,float &q)
{
p=3.14*r*r*h;
q=2*3.14*r*(r+h);
}
int main(void)
{
float a,b,c,p,q,n;
cout<<"Enter any number between 1-6 ";
cin>>n;
if(n==1)
{
cout<<"Enter the radius of the circle ";
cin>>a;
compute_Circle(a,p,q);
cout<<"Area= "<<p<<" Circumference= "<<q;
}
if(n==2)
{
cout<<"Enter the length and the width of the rectangle ";
cin>>a>>b;
compute_Rectangle(a,b,p,q);
cout<<"Area= "<<p<<" Perimeter= "<<q;
}
if(n==3)
{
cout<<"Enter the sides of the triangle ";
cin>>a,b,c;
compute_Triangle(a,b,c,p,q);
cout<<"Area= "<<p<<" Perimeter= "<<q;
}
if(n==4)
{
cout<<"Enter the radius of the sphere ";
cin>>a;
compute_Sphere(a,p,q);
cout<<"Volume= "<<p<<" Surface area= "<<q;
}
if(n==5)
{
cout<<"Enter the radius and the height of the cylinder ";
cin>>a>>b;
compute_Cylinder(a,b,p,q);
cout<<"Volume= "<<p<<" Surface area= "<<q;
}
if(n==6)
exit;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.