Box It!

Sort by

recency

|

459 Discussions

|

  • + 0 comments

    Anyone confused where to get the input and output format for this problem ==> Change the version from cpp 20 to 14. This will populate the editor with a 'check' function and some comments to explain.

  • + 0 comments

    whoever designed the test is very similar to a customer..

    half of the info about what the expected behaviour is,

    half of the info regarding operating ranges,

    no info on inputs or any other systems around this...

    Amazing !!!

  • + 0 comments
    class Box
    {
    private:
        int m_length, m_breadth, m_height;
    
    public:
        Box()
        {
            m_length = 0;
            m_breadth = 0;
            m_height = 0;
        }
        Box(int length, int breadth, int height)
        {
            m_length = length;
            m_breadth = breadth;
            m_height = height;
        }
        Box(Box &box)
        {
            m_length = box.getLength();
            m_breadth = box.getBreadth();
            m_height = box.getHeight();
        }
        int getLength()
        {
            return m_length;
        }
        int getBreadth()
        {
            return m_breadth;
        }
        int getHeight()
        {
            return m_height;
        }
        long long CalculateVolume()
        {
            return 1LL * m_length * m_breadth * m_height;
        }
        bool operator<(Box &box)
        {
            if (m_length < box.getLength())
            {
                return true;
            }
            else if (m_breadth < box.getBreadth() &&
                     m_length == box.getLength())
            {
                return true;
            }
            else if (m_height < box.getHeight() &&
                     m_breadth == box.getBreadth() &&
                     m_length == box.getLength())
            {
                return true;
            }
    
            return false;
        }
    };
    
    ostream &operator<<(ostream &out, Box &box)
    {
        return out << box.getLength() << " " << box.getBreadth() << " " << box.getHeight();
    };
    
  • + 0 comments
    class Box {
    private:
        int l = 0, b = 0, h = 0;
        
    public:
        Box() = default;
        Box(int l, int b, int h)
            : l(l), b(b), h(h) {}
        Box(const Box& other)
            : l(other.l), b(other.b), h(other.h) {}
            
        int getLength() { return l; }
        int getBreadth() { return b; }
        int getHeight() { return h; }
        
        long long CalculateVolume() { return (long)(l * b) * h; }
        
        bool operator<(Box& other) { 
            if (this->l < other.l) return true;
            else if ((this->b < other.b) && (this->l == other.l)) return true;
            else if ((this->h < other.h) && (this->l == other.l) && (this->b == other.b)) return true;
            else return false;
        }
        friend ostream& operator<<(ostream& oss, Box &box) {
            oss << box.l << " " << box.b << " " << box.h;
            return oss;
        }
    };
    
  • + 0 comments

    The test is poorly designed, as it doesn't account for its own overflows. Nor does it account for modern C++ features or CLANG features.