Saturday, May 15, 2021

C++ slip2 solution

slip 2

a) Write a C++ program to find volume of cylinder, cone and sphere. (Use function overloading). 


#include<iostream.h>

float vol(int,int);

float vol(float,int);

int vol(int);


int main()

 {

   int radius,height,height2 ;

   float radius1,radius2;

  clrscr();

   cout<<"Enter the radius and height of the cylinder :" ;

   cin>>radius>>height;

   cout<<Enter the radius and height of the Cone :  ";

   cin>>radius2>>height2;

   cout<<"Enter radius of sphere: ";

   cin>>radius1;

    cout<<"Volume of Cylinder is "<<vol(radius,height);

   cout<<"Volume of Cone is"<<vol(radius2,height2);

   cout<<"Volume of Sphere is "<<vol(radius1);

   getch();

   return 0;

}


float vol(int radius , int height)

  {

   return(3.14 * radius* radius* height);

}


 int vol(float radius2, int height2)

  { 

    return(0.33*3.14 *radius2*radius2*height2);

}

int vol(int radius1)

{

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

}

No comments:

Post a Comment

Slip 10. Write a jQuery code to make first word of each statement to bold.

  Slip 10. Write a jQuery code to make first word of each statement to bold.  <!DOCTYPE html> <html>   <head>     <scri...