Box It!

  • + 0 comments

    class Box { private: int l, b, h;

    public: // Constructors Box() : l(0), b(0), h(0) {} Box(int length, int breadth, int height) : l(length), b(breadth), h(height) {} Box(const Box& other) : l(other.l), b(other.b), h(other.h) {}

    // Getters
    int getLength() const { return l; }
    int getBreadth() const { return b; }
    int getHeight() const { return h; }
    
    // Volume
    long long CalculateVolume() const {
        return 1LL * l * b * h;
    }
    
    // Lexicographic comparison: (l, b, h)
    bool operator<(const Box& other) const {
        if (l != other.l) return l < other.l;
        if (b != other.b) return b < other.b;
        return h < other.h;
    }
    
    // Output operator
    friend ostream& operator<<(ostream& out, const Box& B) {
        out << B.l << " " << B.b << " " << B.h;
        return out;
    }
    

    };