-
Notifications
You must be signed in to change notification settings - Fork 222
/
box-it.cpp
59 lines (51 loc) · 1.6 KB
/
box-it.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
class Box {
int l, b, h;
public:
Box() {
l = 0, b = 0, h = 0;
}
Box(int nl, int nb, int nh) {
l = nl, b = nb, h = nh;
}
Box(const Box& box) {
l = box.getLength();
b = box.getBreadth();
h = box.getHeight();
}
int getLength() const {return l;}
int getBreadth() const {return b;}
int getHeight() const {return h;}
long long CalculateVolume() {
long long ret = l;
ret *= b;
ret *= h;
return ret;
}
bool operator<(const Box& box) {
bool ret = false;
if (l < box.getLength())
ret = true;
else if (l == box.getLength() && b < box.getBreadth())
ret = true;
else if (l == box.getLength() && l == box.getBreadth() && h < box.getHeight())
ret = true;
return ret;
}
friend std::ostream& operator<<(ostream& out, const Box& B);
};
std::ostream& operator<<(std::ostream& out, const Box& box) {
out << box.getLength() << ' ' << box.getBreadth() << ' ' << box.getHeight();
return out;
}
// Constructors:
// Box();
// Box(int,int,int);
// Box(Box);
// int getLength(); // Return box's length
// int getBreadth (); // Return box's breadth
// int getHeight (); //Return box's height
// long long CalculateVolume(); // Return the volume of the box
//Overload operator < as specified
//bool operator<(Box& b)
//Overload operator << as specified
//ostream& operator<<(ostream& out, Box& B)