Programming

C++ Program to Find Volume of Cube, Cylinder – Constructor Overloading

Find the volume of cube, cylinder and rectangular box using the concept of constructor overloading.

Source Code

#include<stdio.h>

#include<iostream>

#include<conio.h>

using namespace std;

class vol

{

    int l;

    int b;

    int r;

    int h;

public:

vol(int a)

    {

        l=a;

    }

vol(int a,int b)

    {

        r=a;

        h=b;

    }

vol(int a,int d,int c)

    {

        l=a;

        b=d;

        h=c;

    }

void cube()

    {

        cout<<"Volume of Cube:  "<<l*l*l << endl;

    }

void cyli() {

            cout<<"Volume of Cylinder: "<<3.14*r*r*h <<endl;

        }

            void rec()

            {

                cout<<"Volume of Rect.Box:  "<<l*b*h << endl;

            }

};

int main()

{

    vol v1(2);

    v1.cube();

    vol v2(3,4);

    v2.cyli();

    vol v3(1,2,3);

    v3.rec();

    getch();

}

Output

Find Volume of Cube

Tuts

About Author

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.