You are viewing a single comment's thread. Return to all comments →
class Box { private: int length, breadth, height; public: // Constructors Box() : length(0), breadth(0), height(0) {} Box(int l, int b, int h) : length(l), breadth(b), height(h) {} Box(const Box& box) : length(box.length), breadth(box.breadth), height(box.height) {} // Getter functions int getLength() { return length; } int getBreadth() { return breadth; } int getHeight() { return height; } // Calculate volume long long CalculateVolume() { return static_cast<long long>(length) * breadth * height; } // Operator overloading < bool operator<(const Box& b) { if (length < b.length) return true; else if (length == b.length && breadth < b.breadth) return true; else if (length == b.length && breadth == b.breadth && height < b.height) return true; else return false; } // Operator overloading << friend ostream& operator<<(ostream& out, const Box& B) { out << B.length << " " << B.breadth << " " << B.height; return out; } };
Seems like cookies are disabled on this browser, please enable them to open this website
Box It!
You are viewing a single comment's thread. Return to all comments →