Write a program using constructor overloading to implement the following tasks:
1.Print sides of a cube
2.Print radius and height of the cylinder
3.Calculate the volume of a cube
4.Calculate thevolume of a cylinder
#include<bits/stdc++.h>
using namespace std;
class dimensions
{
public:
float len_cube,r,h;
dimensions(float len_cube)
{
float area;
cout<<"Length of sides of cube are : "<<len_cube;
area=len_cube*len_cube*len_cube;
cout<<"\nVolume of cube = "<<area;
}
dimensions(float r,float h)
{
float area;
cout<<"Dimensions of cylinder are,\nHeight : "<<h<<"\nRadius : "<<r;
area=3.14*r*r*h;
cout<<"\nVolume of cylinder = "<<area;
}
};
Comments
Leave a comment