1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
/* Design a program to approximate the volume of cheese in a rectangular hunk of swiss cheese.
input:Radius of the sphere, radius and height of cylinder, height, lengths, width of rectangular
parallelapiped.
output: Ask for height, length, width of hunk in cm. Ask for total bubbles. Ask for total holes
Tell total volume based on calculations
processing: Void function confirms dimensions entered are greater than 0
Void function confirms bubble count is greater than 0
Value returning function to find Volume of sphere = 4/3*(3.14159)*r*r*r
Value returning function to find Volume of cylinder = 3.14159*r*r*h
Value returning function to find Volume of rectangle = h*l*w
Value returning function to find Total volume of cheeze = volume rectangle - cylinders - spheres
*/
#include <iostream>
using namespace std;
void confirmDimension (int dim,char what);
void confirmBubbles (int bubbles);
int sphereVolume (int r);
int cylinderVolume (int rad,int h);
int recVolume (int h,int l, int w);
int total (int w,int l, int h, int bubbles, double radbubble, int cylinders, double radcyl, double heightcyl);
int main ()
{
double height,length,width,bubbles,bubRadius,holes,tot,radiuscyl, heightcyl;
cout<<"Enter the height, length and width of the hunk of cheese in centimeters.";
cin>>height;
confirmDimension (height,'ht');
cin>>length;
confirmDimension (length,'lg');
cin>>width;
confirmDimension (width,'wd');
cout<<"How many spherical bubbles are present?";
cin>>bubbles;
confirmDimension (bubbles,'bb');
cout<<"What is the radius of the spherical bubbles in centimeters?";
cin>>bubRadius;
confirmDimension (bubRadius,'rad');
cout<<"How many cylindrical holes are present?";
cin>>holes;
confirmDimension (holes,'hl');
cout<<"What is the radius and height of the surface cylinders in centimeters?";
cin>>radiuscyl;
confirmDimension (radiuscyl,'rc');
cin>>heightcyl;
confirmDimension (heightcyl,'hc');
tot = total (width,length, height, bubbles, bubRadius, holes, radiuscyl, heightcyl);
cout<<"The total volume of cheese present is "<<tot<< "cubic centimeters.";
return 0;
}
/* function to make sure users input is greater than 0
input: any value from user
output: same value or new value greater than 0
processing: while loop to determine greater than 0
*/
void confirmDimension (int dimension,char what)
{
if(what=='ht')
{
while (dimension <= 0 )
{
cout<<"The height of hunk of cheese must be greater than zero.";
cin>>dimension;
}
}
else if(what=='lg')
{
while (dimension <= 0 )
{
cout<<"The length of hunk of cheese must be greater than zero.";
cin>>dimension;
}
}
else if(what=='wd')
{
while (dimension <= 0 )
{
cout<<"The width of hunk of cheese must be greater than zero.";
cin>>dimension;
}
}
if(what=='bb')
{
while (dimension <= 0 )
{
cout<<"The number f spherical bubbles must be greater than zero.";
cin>>dimension;
}
}
if(what=='rad')
{
while (dimension <= 0 )
{
cout<<"The radius of spherical bubble must be greater than zero.";
cin>>dimension;
}
}
if(what=='hl')
{
while (dimension <= 0 )
{
cout<<"The number of cylindrical holes must be greater than zero.";
cin>>dimension;
}
}
if(what=='rc')
{
while (dimension <= 0 )
{
cout<<"The radius of the cylindrical holes must be greater than zero.";
cin>>dimension;
}
}
if(what=='hc')
{
while (dimension <= 0 )
{
cout<<"The height of thee cylindrical holes must be greater than zero.";
cin>>dimension;
}
}
}
/* function to make sure users input is greater than 0
input: bubbles
output: same value or new value greater than 0
processing: while loop to determine greater than 0
*/
void confirmBubbles (int bubbles)
{
while (bubbles <= 0 )
cout<<"The number of spherical bubbles must be greater than 0.";
cin>>bubbles;
}
/* function to find volume of the sphere
input: radius
output: volume
processing: volume = 4/3*(3.14159)*r*r*r
*/
int sphereVolume (int r)
{
double volumes;
volumes = 4/3*(3.14159)*r*r*r;
return volumes;
}
/* function to find volume of the cylinder
input: radius, height
output: volume
processing: volume = 3.14159*rad*rad*h
*/
int cylinderVolume (int rad,int h)
{
double volumec;
volumec = 3.14159*rad*rad*h;
return volumec;
}
/* function to find volume of the rectangular object
input: height, length, width
output: volume
processing: volume = h*l*w
*/
int recVolume (int h,int l, int w)
{
double volumer;
volumer = h*l*w;
return volumer;
}
/* function to find total volume of the cheese
input: width, length, height, bubbles, radius of bubbles, cylinders, radius of cylinders, height of cylinder
output: volume of cheese
processing: Call function to find volume of sphere, call function to find volume of cylinders,
parallelepiped volume - spheresvolume - cylinders volume = total parallelepiped
*/
int total (int wid,int len, int hei, int bubbles, double radbubble, int cylinders, double radcyl, double heightcyl)
{
double S,C,R,total;
S = sphereVolume (radbubble);
C = cylinderVolume (radcyl, heightcyl);
R = recVolume (wid, len, hei);
total = R-C-S;
return total;
}
|