Reference no: EM132356128
Goals: Developing problem-solving skills and functions
Problem: You will create a program that will approximate the volume of cheese in a rectangular hunk of Swiss cheese. For this approximation, you will assume that the holes in the Swiss cheese are of two types: spherical bubbles (all of the same size) or cylindrical holes (all of the same size) which are connected to the surface.
The volume of cheese is the volume of the hunk of cheese minus the volume due to spherical bubbles and cylindrical holes. Your program should include 6 functions in addition to your main function.
• A function that will robustly confirm that the dimension entered is greater than zero. This function should accept the dimension and what it is such as "height of the hunk of cheese", "radius of spherical bubble", etc. The function should return a valid value.
• A function that will robustly confirm that the number entered for spherical bubbles is greater than zero. This function should accept the number and if it is for spherical bubbles or surface cylinders. The function should return a valid value.
• A that function will accept the radius of a sphere then calculate and return the volume of a sphere (vol = 4/37tr3).
• A function that will accept the radius and height of a cylinder, then calculate and return the volume of a cylinder (vol = mr2h)
• A value returning function that accept the height, length, and width of a rectangular hunk of cheese then calculate and return the volume of the rectangular hunk of cheese (vol = hlw).
• A value returning function that will accept 8 parameters: width, length, and height of the rectangular hunk of cheese; the number of spherical bubbles and the radius of the bubbles; plus the number of cylindrical holes in contact with a surface and the radius and height of these cylinders.
This function will call the functions to calculate the volumes of a single bubble and of a single cylindrical pore, calculate the total volume due to spherical bubbles and the total volume due to cylindrical pores, subtract the volumes of spherical bubbles and surface cylinders from the total possible volume of the rectangular hunk of chees. This final volume should be returned to the function call.
Your main function should ask the user to input the dimensions of the rectangular hunk of cheese, the number and size of the spherical bubbles, and the number and dimensions of the surface cylinders.
For each of these 8 values your main function should call the functions to confirm input is greater than 0. After this confirmation, the function to approximate the volume of cheese should be called. Then the main function should output the approximate volume of cheese present. You may assume that the total volume of spherical bubbles and surface cylinders will not exceed the volume of the original hunk.
Make sure your submission follows the assignment guidelines posted on Canvas. The value of pi may be declared globally as 3.14159. You may assume the user will enter values of correct data type.
Some example outputs are given below. The user's input is shown in bold.
Example :
Enter the height of the hunk of cheese in centimeters. 25.8
Enter the length of the hunk of cheese in centimeters. 40.67
Enter the width of the hunk of cheese in centimeters. 35.5
How many spherical bubbles are present? 10
What is the radius of the spherical bubbles in centimeters? 1.2
How many cylindrical holes are present? 8
What is the radius of the cylindrical holes in centimeters? 0.8
What is the height of the cylindrical holes in centimeters? 4