-
Notifications
You must be signed in to change notification settings - Fork 0
/
constructor_overloading.cpp
71 lines (67 loc) · 1.09 KB
/
constructor_overloading.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<iostream>
using namespace std;
class volume{
private:
int volu;
public:
volume(int a);
volume(float r);
volume(int l,int b,int h);
volume(int r,int h);
};
volume::volume(int a)
{
volu=a*a*a;
cout<<"volume of cube is"<<volu;
}
volume::volume(float r)
{
volu=((4/3)*3.14*r*r*r);
cout<<"volume of sphere is"<<volu;
}
volume::volume(int l,int b,int h)
{
volu=l*b*h;
cout<<"volume of rectangle is"<<volu;
}
volume::volume(int r,int h)
{
volu=3.14*r*r*h;
cout<<"volume of cylinder is"<<volu;
}
int main()
{
int c,i,a,l,r,h,b;
float ra;
do
{
cout<<"choose option 1.cube 2.sphere 3.rectangle 4.cylinder";
cin>>c;
if(c==1)
{
cout<<"enter side";
cin>>a;
volume p( a);
}
else if(c==2)
{
cout<<"enter radius";
cin>>ra;
volume q( ra);
}
else if(c==3)
{
cout<<"enter length,breadth and height of rectangle";
cin>>l>>b>>h;
volume r( l, b, h);
}
else
{
cout<<"enter radius and height of cylinder";
cin>>r>>h;
volume s( r, h);
}
cout<<"do you want to continue";
cin>>i;
}while(i=1);
}