| 6 | #include <algorithm> // For the std::min()/max() function templates |
| 7 | |
| 8 | class Box |
| 9 | { |
| 10 | public: |
| 11 | Box() = default; |
| 12 | Box(double length, double width, double height) |
| 13 | : m_length{length}, m_width{width}, m_height{height} {}; |
| 14 | |
| 15 | double volume() const |
| 16 | { |
| 17 | return m_length * m_width * m_height; |
| 18 | } |
| 19 | |
| 20 | int compare(const Box& box) const |
| 21 | { |
| 22 | if (volume() < box.volume()) return -1; |
| 23 | if (volume() == box.volume()) return 0; |
| 24 | return +1; |
| 25 | } |
| 26 | |
| 27 | friend std::ostream& operator<<(std::ostream& out, const Box& box) |
| 28 | { |
| 29 | return out << std::format("Box({:.1f},{:.1f},{:.1f})", box.m_length, box.m_width, box.m_height); |
| 30 | } |
| 31 | |
| 32 | Box operator+(const Box& aBox) const // Function to add two Box objects |
| 33 | { |
| 34 | return Box{ std::max(m_length, aBox.m_length), |
| 35 | std::max(m_width, aBox.m_width), |
| 36 | m_height + aBox.m_height }; |
| 37 | } |
| 38 | |
| 39 | private: |
| 40 | double m_length {1.0}; |
| 41 | double m_width {1.0}; |
| 42 | double m_height {1.0}; |
| 43 | }; |
| 44 | |
| 45 | #endif |
nothing calls this directly
no outgoing calls
no test coverage detected