In this HackerRank Box It! problem in c++ we need to design a class named Box whose dimensions are integers and private to the class and a copy constructor Box that show set the dimensions of the Box class and the four functions getLength() to return the length of the box, getBreadth() to return box's breadth, getHeight() to return box's height and CalculateVolume() to return volume of the box.

HackerRank Box It! in C++ problem solution

HackerRank Box It! in C++ problem solution

class Box{
    int l, b, h;
public:
    Box();
    Box(int d, int e, int f);    
    Box(Box const& rhs);
    
    ~Box(){
        ++BoxesDestroyed;
    }
    
    int getLength() const{
        return l;
    }
    
    int getBreadth() const{
        return b;        
    }
    
    int getHeight() const{
        return h;
    }
    
    long long CalculateVolume(){
        return static_cast<long long>(l) * static_cast<long long>(b) * h;
    }      
};

Box::Box() : l{0}, b{0}, h{0}{
    ++BoxesCreated;
}

Box::Box(int d, int e, int f) : l{d}, b{e}, h{f}{
    ++BoxesCreated;
}

Box::Box(Box const& rhs) : l{rhs.l}, b{rhs.b}, h{rhs.h}{
    ++BoxesCreated;
}

bool operator<(Box const& lhs, Box const& rhs){
        if(lhs.getLength() < rhs.getLength()){
            return true;
        }
        if((lhs.getLength() == rhs.getLength()) && (lhs.getBreadth() < rhs.getBreadth())){
            return true;
        }
        if((lhs.getLength() == rhs.getLength()) && (lhs.getBreadth() == rhs.getBreadth()) && (lhs.getHeight() < rhs.getHeight())){
            return true;
        }
        return false;
    }    

ostream& operator<<(ostream& os, Box const rhs){
    os << rhs.getLength() << " " << rhs.getBreadth() << " " << rhs.getHeight();
    return os;    
}
//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);

// 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

//Overload operator << as specified