Box It!

  • + 0 comments
    class Box
    {   
        //friend bool operator<(Box& A, Box& B);
        friend ostream& operator<<(ostream&out, Box& B);
        private:
            int l;
            int b;
            int h;
        public:
            Box(): l(0), b(0), h(0){};
            Box(const Box& B)
            {
                this->l = B.l;
                this->b = B.b;
                this->h = B.h;
            }
            Box(int l, int b, int h): l(l), b(b), h(h){}
            bool operator<(Box& B)
            {
                if(this->l < B.l)
                {
                    return true;
                }
                else if(this->b < B.b && this->l == B.l)
                {
                    return true;
                }
                else if(this->h < B.h && this->b == B.b && this->l == B.l)
                {
                    return true;
                }
                else 
                    return false;
            }
            bool operator==(Box& B)
            {
                if(this->l == B.l && this->b == B.b && this->h == B.h)
                {
                    return true;
                }
                else 
                {
                    return false;
                }
            }
            Box& operator=(Box& B)
            {
                if(*this == B)
                {
                    return *this;
                }
                this->l = B.l;
                this->b = B.b;
                this->h = B.h;
                
                return *this;
            }
            int getLength()
            {
                return this->l;
            }
            
            int getBreadth()
            {
                return this->b;
            }
            
            int getHeight()
            {
                return this->h;
            }
            long long CalculateVolume()
            {
                return ((long long)(l) * b * h);
            }
    };
    ostream& operator<<(ostream& out, Box& B)
    {
        out << B.l << " " << B.b << " " << B.h << " ";
        return out;
    }