Search This Blog

Monday 25 January 2016

Write a program which calculates volume of cube, cylinder, and rectangular box. (Use function overloading).

Practical 8


#include<iostream.h>
using namespace std;

int volume(int s)
{
    return s*s*s;
}
double volume(double r,int h)
{
    return 3.14*r*r*h;
}
float volume(float l,int b,int h)
{
    return l*b*h;
}
int main()
{
    int x,s,h,b;
    double y,r;
    float z,l;
    cout<<"\nEnter the value of s for cube:";
    cin>>s;
    x=volume(s);
    cout<<"\nVolume of cube is:"<<x<<endl;
    cout<<"\nEnter the value of r & h for cylinder:";
    cin>>r>>h;
    y=volume(r,h);
    cout<<"Volume of cylender is"<<y<<endl;
    cout<<"\nEnter valu of l,b & h:";
    cin>>l>>b>>h;
    z=volume(l,b,h);
    cout<<"\nVolume of rectangle:"<<z;
    return 0;
}



output:

enter the value f s for cube:2
volume of cube is 8

enter the value of r & h for cylinder
10
10
volume of cylinder is 314

enter the value of l b h
2
4
2
volume of rectangle is 16

No comments:

Post a Comment