-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathInheritanceExample188.cpp
More file actions
102 lines (79 loc) · 1.58 KB
/
Copy pathInheritanceExample188.cpp
File metadata and controls
102 lines (79 loc) · 1.58 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include<iostream>
using namespace std;
class Rectangle
{
private:
int length;
int breadth;
public:
Rectangle();
Rectangle(int l,int b);
Rectangle(Rectangle &r);
int getLength(){return length;}
int getBreadth(){return breadth;}
void setLength(int l);
void setBreadth(int b);
int area();
int perimeter();
bool isSquare();
~Rectangle();
};
class Cuboid:public Rectangle
{
private:
int height;
public:
Cuboid(int h)
{
height=h;
}
int getHeight(){return height;}
void setHeight(int h){height=h;}
int volume(){return getLength()*getBreadth()*height;}
};
int main()
{
Cuboid c(5);
c.setLength(10);
c.setBreadth(7);
cout<<"Volume is "<<c.volume()<<endl;
}
Rectangle::Rectangle()
{
length=1;
breadth=1;
}
Rectangle::Rectangle(int l,int b)
{
length=l;
breadth=b;
}
Rectangle::Rectangle(Rectangle &r)
{
length=r.length;
breadth=r.breadth;
}
void Rectangle::setLength(int l)
{
length=l;
}
void Rectangle::setBreadth(int b)
{
breadth=b;
}
int Rectangle::area()
{
return length*breadth;
}
int Rectangle::perimeter()
{
return 2*(length+breadth);
}
bool Rectangle::isSquare()
{
return length==breadth;
}
Rectangle::~Rectangle()
{
// cout<<"Rectangle Destroyed";
}