# HackerRank ‘Box It!’ Solution

##### Short Problem Definition:

Design a class named Box whose dimensions are integers and private to the class.

Box It!

Does not apply.

Does not apply.

##### Solution:
```// The class should have the following functions :
class Box {
private:
int l=0;
int b=0;
int h=0;
public:
// Constructors:
// Box();
Box() = default;
// Box(int,int,int);
Box(int len, int bre, int hei):
l(len), b(bre), h(hei) {};
// Box(Box);
Box(Box &other):
l(other.l), b(other.b), h(other.h) {};

// int getLength(); // Return box's length
int getLength() { return l;}
// int getHeight ();  //Return box's height
int getHeight() { return h;}

// long long CalculateVolume(); // Return the volume of the box
long long CalculateVolume() { return (long long) l*b*h;}

//bool operator<(Box& b)
bool operator<(Box& b) {
return this->l < b.l ||
(this->b < b.b && this->l == b.l) ||
(this->h < b.h && this->b == b.b && this->l == b.l);
}
};

ostream& operator<<(ostream& out, Box& b) {
out << b.getLength() << " ";
out << b.getBreadth() << " ";
out << b.getHeight() << " ";

return out;
}
```

If you enjoyed this post, then make sure you subscribe to my Newsletter and/or Feed.