Box It!

Sort by

recency

|

462 Discussions

|

  • + 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;
    }
    

    };

  • + 0 comments

    class Box {

    private:
        int l;
        int b;
        int h;
    
    public:
    
    Box() : l(0), b(0), h(0) {}
    Box(int l, int b, int h) : l(l), b(b), h(h) {}
    Box(const Box& B) : l(B.l), b(B.b), h(B.h) {}
    
    int getLength() const {return l;}
    int getBreadth() const {return b;}
    int getHeight() const {return h;}
    long long CalculateVolume() const {
        return static_cast<long long>(l) * b * h;
    }
    
    bool operator<(const Box& B) const {
        if (l < B.l) return true;
        if (l == B.l && b < B.b) return true;
        if (l == B.l && b == B.b && h < B.h) return true;
        return false;
    }
    
    friend ostream& operator<<(ostream& out, Box& B){
        out << B.l << " " << B.b << " " << B.h;
        return out;
    }
    

    };

  • + 0 comments

    Okay, so test 3 uses really large numbers and we need to convert current int values into long long BEFORE calculations.

  • + 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 !!!