-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInheritance.cpp
54 lines (46 loc) · 875 Bytes
/
Inheritance.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
#include <iostream>
using namespace std;
class Rectangle{
private:
int length;
int breadth;
public:
Rectangle(int l,int b){
length=1;
breadth=1;
}
void set_length(int l);
void set_breadth(int b);
int get_length(){return length;}
int get_breadth(){return breadth;}
int area(){return length*breadth;}
int perimeter(){return length + breadth;}
};
void Rectangle::set_length (int l){
length=l;
}
void Rectangle::set_breadth(int b){
breadth=b;
}
class cuboid:public Rectangle{
private:
int hieght;
public:
void set_hieght(int h ){
hieght=h;
}
int volume(){
return get_length()*hieght*get_breadth();
}
};
int main(){
Rectangle r1;
cuboid c1;
int l,b;
cout<<"Enter length:";
cin>>l;
c1.set_length(l);
c1.set_breadth(l);
c1.set_hieght(l);
cout<<c1.volume();
}