forked from rahul22mrk/hackoctoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBox It.cpp
65 lines (56 loc) · 1.41 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
#include<bits/stdc++.h>
using namespace std;
//Implement the class Box
//l,b,h are integers representing the dimensions of the box
// The class should have the following functions :
// 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)
class Box{
private :
int l,b,h;
public:
Box(){l=b=h=0;}
Box(int len,int br,int hg){
l = len;
b = br;
h = hg;
}
Box(const Box& B){
l = B.l;
b = B.b;
h = B.h;
}
int getLenght(){
return l;
}
int getBreadth(){
return b;
}
int getHeight(){
return h;
}
long long CalculateVolume(){
return (long long)l*b*h;
}
friend bool operator < ( Box&A,Box& B){
if( (A.l < B.l) || ((A.b < B.b) && (A.l == B.l)) || ((A.h < B.h) && (A.l == B.l) && (A.b == B.b)) ){
return true;
}else{
return false;
}
};
friend ostream& operator<< (ostream& output, const Box& B){
output << B.l << " " << B.b << " " << B.h;
return output;
}
};