#include #include //////////////////////////////////////////////////////////////// // Volumes and surface areas of the five Platonic solides // - This collection of functions will return the volumes // and surface areas of the five Platonic solids: // Faces Shape Vertices Edges // tetrahedron 4 triangle 4 6 // cube 6 square 8 12 // octahedron 8 triangle 6 12 // dodecahedron 12 pentagon 20 30 // icosahedron 20 triangle 12 30 //////////////////////////////////////////////////////////////// // Function declarations int main(); double tetrahedron_volume( double side ); double cube_volume( double side ); double octahedron_volume( double side ); double dodecahedron_volume( double side ); double icosahedron_volume( double side ); double tetrahedron_area( double side ); double cube_area( double side ); double octahedron_area( double side ); double dodecahedron_area( double side ); double icosahedron_area( double side ); // Function definitions int main() { std::cout << "The volume of a tetrahedron with a side length " << 2.0 << " is " << tetrahedron_volume( 2.0 ) << std::endl; std::cout << " - expecting 0.942809041582" << std::endl; std::cout << "The volume of a cube with a side length " << 2.0 << " is " << cube_volume( 2.0 ) << std::endl; std::cout << " - expecting 8" << std::endl; std::cout << "The volume of an octahedron with a side length " << 2.0 << " is " << octahedron_volume( 2.0 ) << std::endl; std::cout << " - expecting 3.77123616633" << std::endl; std::cout << "The volume of a dodecahedron with a side length " << 2.0 << " is " << dodecahedron_volume( 2.0 ) << std::endl; std::cout << " - expecting 61.3049516850" << std::endl; std::cout << "The volume of an icosahedron with a side length " << 2.0 << " is " << icosahedron_volume( 2.0 ) << std::endl; std::cout << " - expecting 17.4535599250" << std::endl; std::cout << "The surface area of a tetrahedron with a side length " << 2.0 << " is " << tetrahedron_area( 2.0 ) << std::endl; std::cout << " - expecting 6.92820323028" << std::endl; std::cout << "The surface area of a cube with a side length " << 2.0 << " is " << cube_area( 2.0 ) << std::endl; std::cout << " - expecting 24" << std::endl; std::cout << "The surface area of an octahedron with a side length " << 2.0 << " is " << octahedron_area( 2.0 ) << std::endl; std::cout << " - expecting 13.8564064606" << std::endl; std::cout << "The surface area of a dodecahedron with a side length " << 2.0 << " is " << dodecahedron_area( 2.0 ) << std::endl; std::cout << " - expecting 82.5829152283" << std::endl; std::cout << "The surface area of an icosahedron with a side length " << 2.0 << " is " << icosahedron_area( 2.0 ) << std::endl; std::cout << " - expecting 34.6410161514" << std::endl; return 0; } ////////////////////////////////////////////////////////// // Volume of a tetrahedron // // @author Douglas Wilhelm Harder // @date 2018-09-17 // @version 1.0 // // @param side the length of a side of the tetrahedron // @return the volume of the tetrahedron // - the units of the return value is the cube // of the units of whatever the user passed // - if the user passes inches, // the result is cubic inches // - if the user passes cm, // the result is cm^3 // // @section FORMULA // If 's' is the length of a side: // 3 / _ // s / 6 \/2 ////////////////////////////////////////////////////////// double tetrahedron_volume( double side ) { return side*side*side/(6.0*std::sqrt(2.0)); } ////////////////////////////////////////////////////////// // Volume of a cube // // @author Douglas Wilhelm Harder // @date 2018-09-17 // @version 1.0 // // @param side the length of a side of the cube // @return the volume of the cube // - the units of the return value is the cube // of the units of whatever the user passed // - if the user passes inches, // the result is cubic inches // - if the user passes cm, // the result is cm^3 // // @section FORMULA // If 's' is the length of a side: // 3 // s ////////////////////////////////////////////////////////// double cube_volume( double side ) { return 0.0; } ////////////////////////////////////////////////////////// // Volume of a octahedron // // @author Douglas Wilhelm Harder // @date 2018-09-17 // @version 1.0 // // @param side the length of a side of the octahedron // @return the volume of the octahedron // - the units of the return value is the cube // of the units of whatever the user passed // - if the user passes inches, // the result is cubic inches // - if the user passes cm, // the result is cm^3 // // @section FORMULA // If 's' is the length of a side: // 1 _ 3 // - \/2 s // 3 ////////////////////////////////////////////////////////// double octahedron_volume( double side ) { return 0.0; } ////////////////////////////////////////////////////////// // Volume of a dodecahedron // // @author Douglas Wilhelm Harder // @date 2018-09-17 // @version 1.0 // // @param side the length of a side of the dodecahedron // @return the volume of the dodecahedron // - the units of the return value is the cube // of the units of whatever the user passed // - if the user passes inches, // the result is cubic inches // - if the user passes cm, // the result is cm^3 // // @section FORMULA // 1 _ 3 // - (15 + 7\/5) s // 4 ////////////////////////////////////////////////////////// double dodecahedron_volume( double side ) { return 0.0; } ////////////////////////////////////////////////////////// // Volume of a icosahedron // // @author Douglas Wilhelm Harder // @date 2018-09-17 // @version 1.0 // // @param side the length of a side of the icosahedron // @return the volume of the icosahedron // - the units of the return value is the cube // of the units of whatever the user passed // - if the user passes inches, // the result is cubic inches // - if the user passes cm, // the result is cm^3 // // @section FORMULA // 5 _ 3 // -- (3 + \/5) s // 12 ////////////////////////////////////////////////////////// double icosahedron_volume( double side ) { return 0.0; } ////////////////////////////////////////////////////////// // Surface area of a tetrahedron // // @author Douglas Wilhelm Harder // @date 2018-09-17 // @version 1.0 // // @param side the length of a side of the tetrahedron // @return the surface area of the tetrahedron // - the units of the return value is the cube // of the units of whatever the user passed // - if the user passes inches, // the result is square inches // - if the user passes cm, // the result is cm^2 // // @section FORMULA // If 's' is the length of a side: // _ 2 // \/3 s ////////////////////////////////////////////////////////// double tetrahedron_area( double side ) { return 0.0; } ////////////////////////////////////////////////////////// // Surface area of a cube // // @author Douglas Wilhelm Harder // @date 2018-09-17 // @version 1.0 // // @param side the length of a side of the cube // @return the surface area of the cube // - the units of the return value is the cube // of the units of whatever the user passed // - if the user passes inches, // the result is square inches // - if the user passes cm, // the result is cm^2 // // @section FORMULA // If 's' is the length of a side: // 2 // 6 s ////////////////////////////////////////////////////////// double cube_area( double side ) { return 0.0; } ////////////////////////////////////////////////////////// // Surface area of a octahedron // // @author Douglas Wilhelm Harder // @date 2018-09-17 // @version 1.0 // // @param side the length of a side of the octahedron // @return the surface area of the octahedron // - the units of the return value is the cube // of the units of whatever the user passed // - if the user passes inches, // the result is square inches // - if the user passes cm, // the result is cm^2 // // @section FORMULA // If 's' is the length of a side: // _ 2 // 2 \/3 s ////////////////////////////////////////////////////////// double octahedron_area( double side ) { return 0.0; } ////////////////////////////////////////////////////////// // Surface area of a dodecahedron // // @author Douglas Wilhelm Harder // @date 2018-09-17 // @version 1.0 // // @param side the length of a side of the dodecahedron // @return the surface area of the dodecahedron // - the units of the return value is the cube // of the units of whatever the user passed // - if the user passes inches, // the result is square inches // - if the user passes cm, // the result is cm^2 // // @section FORMULA // ____________ // / _ 2 // 3 \/ 25 + 10 \/5 s ////////////////////////////////////////////////////////// double dodecahedron_area( double side ) { return 0.0; } ////////////////////////////////////////////////////////// // Surface area of a icosahedron // // @author Douglas Wilhelm Harder // @date 2018-09-17 // @version 1.0 // // @param side the length of a side of the icosahedron // @return the surface area of the icosahedron // - the units of the return value is the cube // of the units of whatever the user passed // - if the user passes inches, // the result is square inches // - if the user passes cm, // the result is cm^2 // // @section FORMULA // _ 2 // 5 \/3 s ////////////////////////////////////////////////////////// double icosahedron_area( double side ) { return 0.0; }