-
Notifications
You must be signed in to change notification settings - Fork 133
/
Box It!.cpp
93 lines (82 loc) · 1.66 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
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
//Implement the class Box
//l,b,h are integers representing the dimensions of the box
class Box
{
private:
int l=0;
int b=0;
int h=0;
public:
int getLength() const
{
return l;
}
int getBreadth() const
{
return b;
}
int getHeight() const
{
return h;
}
long long CalculateVolume ()
{
return (long long)l*b*h;
}
Box()
{
BoxesCreated++;
}
Box(int length, int breadth, int height)
{
l=length;
b=breadth;
h=height;
BoxesCreated++;
}
Box(const Box& B)
{
l=B.getLength();
b=B.getBreadth();
h=B.getHeight();
BoxesCreated++;
}
~Box()
{
BoxesDestroyed++;
}
bool operator<(const Box &B)
{
int ll=B.getLength();
int bb=B.getBreadth();
int hh=B.getHeight();
if(l < ll || (b < bb && l==ll) || (h < hh && b==bb && l==ll))
return true;
else
return false;
}
};
ostream& operator<<(ostream& out, Box B)
{
int l=B.getLength();
int b=B.getBreadth();
int h=B.getHeight();
return out<<l<<' '<<b<<' '<<h;
}
// The class should have the following functions :
// Constructors:
// Box();
// Box(int,int,int);
// Box(Box);
// Destructor
// ~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)