| 6 | #include <format> |
| 7 | |
| 8 | class Box |
| 9 | { |
| 10 | public: |
| 11 | // Constructors |
| 12 | Box() = default; |
| 13 | Box(double l, double w, double h) : m_length{ l }, m_width{ w }, m_height{ h } {} |
| 14 | |
| 15 | double volume() const { return m_length * m_width * m_height; } |
| 16 | |
| 17 | // Accessors |
| 18 | double getLength() const { return m_length; } |
| 19 | double getWidth() const { return m_width; } |
| 20 | double getHeight() const { return m_height; } |
| 21 | |
| 22 | std::partial_ordering operator<=>(const Box& otherBox) const |
| 23 | { |
| 24 | return volume() <=> otherBox.volume(); |
| 25 | } |
| 26 | std::partial_ordering operator<=>(double otherVolume) const |
| 27 | { |
| 28 | return volume() <=> otherVolume; |
| 29 | } |
| 30 | |
| 31 | bool operator==(const Box& otherBox) const = default; |
| 32 | |
| 33 | private: |
| 34 | double m_length{ 1.0 }; |
| 35 | double m_width{ 1.0 }; |
| 36 | double m_height{ 1.0 }; |
| 37 | }; |
| 38 | |
| 39 | inline std::ostream& operator<<(std::ostream& stream, const Box& box) |
| 40 | { |
nothing calls this directly
no outgoing calls
no test coverage detected