Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem: create a program that will approximate the volume of cheese in a rectan

ID: 3624701 • Letter: P

Question

Problem: 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 cylinders (also of the same size).

Your program should include 6 functions in addition to your main function:

• A void function that will *robustly confirm that the dimension entered is greater than zero. This function should accept 2 arguments: the dimension and what it is. You will call this function 6 times (to check: height of cheese, length of cheese, width of cheese, radius of spheres, radius of cylinders, height of cylinders).
• A void function that will *robustly confirm that the number entered for holes is greater than zero. This function should accept 2 arguments: the number of holes and if that number is for spherical bubbles or surface cylinders. You will call this function 2 times.
• A value returning function that will accept the radius of a sphere, and then calculate and return the volume of that sphere (vol = 4/3?r3).
• A value returning function that will accept the radius and height of a cylinder, and then calculate and return the volume of that cylinder (vol = ?r2h).
• A value returning function that will accept the height, length, and width of a rectangular parallelepiped and then calculate and return the volume of the rectangular parallelepiped (vol = hlw).
• A value returning function that will accept 8 parameters: (1)width, (2)length, and (3)height of the rectangular hunk of cheese; the (4)number of spherical bubbles and the (5)radius of the bubbles; plus the (6)number of cylindrical holes in contact with a surface and the (7)radius and (8)height of these cylinders. This function will call the functions to calculate the volumes, and then subtract the volumes of spherical bubbles and surface cylinders from the total possible volume of the parallelepiped. The final volume should be returned to main() via the function call.

Your main function should ask the user to input the dimensions of the parallelepiped, 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.
The value of pi should be declared as a constant of 3.14159.

*robustly confirm: if the item in question is invalid, the function will repeatedly check to make sure that valid input is eventually obtained.

Explanation / Answer

using namespace std;

const double PI=3.14;

void ConfirmValues(double hcheese, double lcheese, double wcheese,double radius_sphe,double radius_cyl, double height_cyl)

{

   if(hcheese<0|| lcheese<0 ||wcheese<0 ||radius_sphe|| radius_cyl<0|| height_cyl<0)

    cout<<"Values Should be greater than zero"<<endl;

}

void confirmHoles(int holes,int hole_for)

{

   if(holes<0)

      cout<<"Should be greater than zero"<<endl;

}

double volume_Sphere(double radius)

{

double volume=4/3*(PI*radius*radius*radius);

return volume;

}

double volume_Cylinder(double radius,double height)

{

double volume=(PI*radius*radius*height);

return volume;

}

double volume_parallelepiped(double height,double length,double width)

{

    double volume=height*length*width;

     return volume;

}

double volume_Swisscheese(double hcheese, double lcheese, double wcheese,double radius_sphe,double radius_cyl, double height_cyl,int num_sbubles,int num_cyli)

{

double total_volume;

   total_volume=volume_parallelepiped(hcheese,lcheese,wcheese)-((num_cyli*volume_Cylinder(radius_cyl,height_cyl)+num_sbubles*volume_Sphere(radius_sphe)));

return total_volume;

}

void main()

{

double hcheese,lcheese,wcheese,radius_sphe,radius_cyl, height_cyl;

double totalVolume;

int num_sbubles,int num_cyli;

cout<<"Enter height of cheese:";

cin>> hcheese;

cout<<"Enter length of cheese:";

cin>> lcheese;

cout<<"Enter width of cheese:";

cin>> wcheese;

cout<<"Enter radius of sphere bubbles:";

cin>> radius_sphe;

cout<<"Enter number of sphere bubbles:";

cin>>num_sbubles;

confirmHoles(num_sbubles,1);

cout<<"Enter radius of cylinder bubbles:";

cin>> radius_cyl;

cout<<"Enter radius of cylinder bubbles:";

cin>> height_cyl;

cout<<"Enter number of cylinder bubbles:";

cin>>num_cyli;

confirmHoles(num_cyli,2);

ConfirmValues(hcheese,lcheese,wcheese,radius_sphe,radius_cyl, height_cyl);

//calculate cheese volume

totalVolume=volume_Swisscheese(hcheese,lcheese,wcheese,radius_sphe,radius_cyl, height_cyl,num_sbubles,num_cyli);

cout<<"Total volume of sphere:"<<totalVolume<<endl;

//pause system for a while

system("pause");

}//end main

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote