-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path78. Overloading Cuboid Operator.cpp
130 lines (123 loc) · 2.21 KB
/
78. Overloading Cuboid Operator.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include<iostream>
using namespace std;
class rectangle
{
private:
int length, breadth;
public:
rectangle();
rectangle(int l, int b);
rectangle(rectangle &rect);
void setlength(int l);
void setbreadth(int b);
int getlength();
int getbreadth();
int area();
~rectangle();
};
class cuboid: public rectangle
{
private:
int height;
public:
cuboid();
cuboid(int l, int b, int h);
cuboid(cuboid &cub);
void setheight(int h);
int getheight();
int getvolume();
~cuboid();
friend ostream& operator<<(ostream &a, cuboid &c);
};
ostream& operator<<(ostream &a, cuboid &c)
{
a<<endl<<endl<<"cout overloaded results"<<endl<<"Length is: "<<c.getlength()<<endl<<"Height is: "<<c.getheight()<<endl<<"Breadth is: "<<c.getbreadth()<<endl;
return a;
}
rectangle::rectangle()
{
length=0;
breadth=0;
}
rectangle::rectangle(int l, int b)
{
length=l;
breadth=b;
}
rectangle::rectangle(rectangle &rect)
{
length=rect.length;
breadth=rect.breadth;
}
void rectangle::setlength(int l)
{
length=l;
}
void rectangle::setbreadth(int b)
{
breadth=b;
}
int rectangle::getlength()
{
return length;
}
int rectangle::getbreadth()
{
return breadth;
}
int rectangle::area()
{
return getbreadth()*getlength();
}
rectangle::~rectangle()
{
cout<<"Destroying rectangle"<<endl;
}
cuboid::cuboid()
{
setlength(0);
setbreadth(0);
height=0;
}
cuboid::cuboid(int l, int b, int h)
{
setbreadth(b);
setlength(l);
setheight(h);
}
cuboid::cuboid(cuboid &cub)
{
setlength(cub.getlength());
setbreadth(cub.getbreadth());
setheight(cub.height);
}
int cuboid::getheight()
{
return height;
}
void cuboid::setheight(int h)
{
height=h;
}
int cuboid::getvolume()
{
return getlength()*getbreadth()*getheight();
}
cuboid::~cuboid()
{
cout<<"Destroying cuboid"<<endl;
}
int main()
{
cuboid c;
c.setlength(12);
c.setbreadth(10);
c.setheight(5);
cout<<"Length is: "<<c.getlength()<<endl;
cout<<"Breadth is: "<<c.getbreadth()<<endl;
cout<<"Height is: "<<c.getheight()<<endl;
cout<<"Volume is: "<<c.getvolume()<<endl;
cout<<"Area is: "<<c.area()<<endl;
cout<<c<<endl<<endl;
return 0;
}