#include struct Box { double width; double length; double height; }; bool isValidBox(Box b); double surface(Box b); int main() { Box box1 = { 2.0, 3.0, 4.0 }; Box box2 = { 0.0, -2.0, 5.0 }; Box box3 = { 7.0, 3.0, 4.0 }; std::cout << "isValidBox( { 2, 3, 4 } ) = " << std::boolalpha << isValidBox( box1 ) << "\n"; std::cout << "isValidBox( { 0, -2, 5 } ) = " << std::boolalpha << isValidBox( box2 ) << "\n"; std::cout << "isValidBox( { 7, 3, 4 } ) = " << std::boolalpha << isValidBox( box3 ) << "\n"; std::cout << "surface( { 3, 5, 9 } ) = " << surface( box1 ) << "\n"; std::cout << "surface( { 1, 12, 3 } ) = " << surface( box2 ) << "\n"; std::cout << "surface( { 1, 2, 3 } ) = " << surface( box3 ) << "\n"; return 0; } //---------------------------------------------------------------------------- // @description check whether the box is a valid box // @param b a box // @return true if the box is valid, false otherwise // @contract isValidBox : Box -> boolean // @example isValidBox( {3, 5, 9 } ) = true // @example isValidBox( {0, -2, 3 } ) = false // @example isValidBox( {1, 2, 3 } ) = true //---------------------------------------------------------------------------- bool isValidBox(Box b) { return (b.width > 0) && (b.length > 0) && (b.height > 0); } //---------------------------------------------------------------------------- // @description calculate the area of the outside surface of a box // @param b a box // @return the area of the outside surface of a box // @contract surface : Box -> double // @example surface( {3, 5, 9 } ) = 15*2 + 45*2 + 27*2 = 174 // @example surface( {1, 12, 3 } ) = 12*2 + 36*2 + 3*2 = 82 // @example surface( {1, 2, 3 } ) = 2*2 + 6*2 + 3*2 = 22 //---------------------------------------------------------------------------- double surface(Box b) { return ( (b.width * b.length) + (b.length * b.height) + (b.height * b.width) ) * 2; }