/* Problem Statement: This program should ask the user to input the height and radius of a cone (both floating point type) and call 4 individual functions to calculate the area of the cone, the base area of the cone, the surface area of the cone, and the volume of the cone. The main function then prints these values. Math Refresher: Volume = 1/3 * PI * radius^2 * height Area = PI * radius * slantHeight; where slantHeight = sqrt(radius^2 + height^2) Area of the base = PI * radius^2 Surface Area = area of the cone + area of the base */ #include #include #include double returnVolume (double radius, double height) { return (1.0/3 * M_PI * radius * radius * height); } // You can choose to give the students the freedom of calculating the // slant height of the cone in their main function and pass that as a // parameter, or restrict the calculation of the slant height to // the called funtions (such as done here in the funtion returnConeArea()) double returnConeArea (double radius, double height) { double slantHeight = sqrt (radius*radius + height*height); return (M_PI * radius * slantHeight); } double returnBaseArea (double radius) { return (M_PI * radius * radius); } // In this function too, you can allow the student to pass the calculated // values of Base Area and Cone Area (as done here) or make them calculate // these values inside the funtion double returnSurfaceArea (double coneArea, double baseArea) { return (baseArea + coneArea); } int main() { double radius, height; printf ("Enter the radius of the cone: "); scanf ("%lf", &radius); printf ("Enter the height of the cone: "); scanf ("%lf", &height); // The slant height is being calculated in the called functions double baseArea = returnBaseArea (radius); double coneArea = returnConeArea (radius, height); double surfaceArea = returnSurfaceArea (baseArea, coneArea); double volume = returnVolume (radius, height); printf ("Given radius: %lf\n", radius); printf ("Given height: %lf\n", height); printf ("The base area of the cone is: %lf\n", baseArea); printf ("The cone area of the cone is: %lf\n", coneArea); printf ("The surface area of the cone is: %lf\n", surfaceArea); printf ("The volume of the cone is: %lf\n", volume); system ("pause"); return (0); }