Find volume of sphere ,cylinder(πr2h) and cube using function overloading.C++

 /*function overloading -- same function name but different purpose along with unique signatures(datatypes, number of arguments )*/

/* To find volume of sphere ,cylinder(πr2h) and cube using function overloading*/
#include <iostream>
#include <math.h>

using namespace std;

const float pie = 3.14;
void volume(float a)
{
    float v = 4.0 / 3 * pie * pow(a3);
    cout << "Volume of sphere is :" << v << endl;
}

void volume(float bfloat c)
{
    cout << "volume of cylinder is : " << (pie * b * b * c<< endl;
}

void volume(int d)
{
    cout << "Volume of cube is : " << pow(d3);
}

int main(void)
{
    float abc;
    int d;
    cout << "enter radius of sphere: ";
    cin >> a;
    volume(a);

    cout << "enter radius and height of cylinder : ";
    cin >> b >> c;
    volume(bc);

    cout << "enter length of cube in integer : ";
    cin >> d;
    volume(d);
}
SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment