forked from durgesh2001/hacktoberfest_demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInheritance.cpp
56 lines (51 loc) · 908 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
55
56
#include<iostream>
#include<string>
using namespace std;
//class
class rectangle
{
public :
//member variables
int length;
int breadth;
//member functions
void show()
{
cout<<"length: "<<length<<"\n";
cout<<"breadth: "<<breadth<<"\n";
}
void area()
{
cout<<"Area->Rectange: "<<length*breadth<<"\n";
}
};
class cuboid:public rectangle //inherit feature of rectangle class
{
public :
int height;
void Display()
{
cout<<"height: "<<height<<"\n";
}
void volume()
{
cout<<"Volume->Cuboid: "<<length*breadth*height<<"\n";
}
};
int main()
{
rectangle r;
r.length=10;
r.breadth=20;
r.show();
r.area();
cuboid c;
c.length=10;
c.breadth=20;
c.height=20;
c.show();
c.Display();
c.area();
c.volume();
return 0;
}