Computer Science, asked by JOJONA, 11 months ago

Write a menu driven program with functions to calculate the volume of the given shapes. The
volume should be displayed using a separate function) Sphere: (pass arguments by value)
=/
b) Cylinder: (pass arguments by reference)
=
c) Cube: (pass arguments by value)
=

Answers

Answered by lovingheart
0

Menu driven program:

#include<iostream>

   using namespace std;

   float vol(int,int);

   float vol(float);

   int vol(int);

     

   int main()

   {

    int r,h,a;

    float r1;

cout << “Menu” <<endl;

cout << “1-->Volume of Cylinder” <<endl;

cout << “2-->Volume of Cube” <<endl;

cout << “3-->Volume of Sphere” <<endl;

cout << “Enter your choice of which you want to perform: ” <<endl;

cin>>choice;

switch(choice)

{

 case 1:

         cout<<"Enter radius and height of a cylinder to calculate volume:";

    cin>>r>>h;

    cout<<"Volume of cylinder is"<<vol(&r,&h);

break;

case 2:

    cout<<"Enter side to calculate volume of a cube:";

    cin>>a;

    cout<<"\nVolume of cube is"<<vol(&a);

break;

case 3:

        cout<<"Enter radius of sphere to calculate its volume:";

            cin>>r1;

       cout<<"\nVolume of sphere is"<<vol(r1);

}

       return 0;

   }

   float volofCylinder(int *r,int *h)

   {

       return(3.14*(*r)*(*r)*(*h));

   }

   float volofCube(float * r1)

   {

       return((4*3.14*(*r1)*(*r1)*(*r1)/3);

   }

   int volofSphere(int a)

   {

       return(a*a*a);

   }

Similar questions