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
|
#include<iostream>
#include <iomanip>
#define PI 3.14159
using namespace::std;
int main() {
void dimChecker(double*, char*);
int countChecker(int, char*);
double calcPercentage(double, double, double, int, double, int, double, double);
double len, wd, ht, bRad, cyRad, cyHt, percent;
int cb;
int cCy;
cout << "Enter length of Sample: ";
cin >> len;
dimChecker(&len, "length of Sample");
cout << "Enter width of Sample: ";
cin >> wd;
dimChecker(&wd, "width of Sample");
cout << "Enter height of Sample: ";
cin >> ht;
dimChecker(&ht, "height of Sample");
cout << "Enter radius of Bubble: ";
cin >> bRad;
dimChecker(&bRad, "radius of Bubble");
cout << "Enter count of Bubble: ";
cin >> cb;
cb = countChecker(cb, "count of Bubble");
cout << "Enter radius of cylinder: ";
cin >> cyRad;
dimChecker(&cyRad, "radius of Cylinder");
cout << "Enter height of Cylinder: ";
cin >> cyHt;
dimChecker(&cyHt, "height of Cylinders");
cout << "Enter count of Cylinder: ";
cin >> cb;
cb = countChecker(cb, "count of Cylinders");
percent = calcPercentage(len, wd, ht, cb, bRad, cCy, cyRad, cyHt);
if (percent<1)
cout << fixed << setprecision(3);
else if (percent<10)
cout << fixed << setprecision(2);
else
cout << fixed << setprecision(1);
cout << percent;
}
void dimChecker(double *dim, char *param) {
while (*dim <= 0) {
cout << "Dimention of " << param << " is not more than zero, please re enter.\n";
cin >> *dim;
}
}
int countChecker(int count, char *param) {
while (count <= 0) {
cout << "Dimention of " << param << " is not more than zero, please re enter a whole number.\n";
cin >> count;
}
return count;
}
double getBubbleVolume(double radius) {
return radius*radius*radius * 4 * PI / 3;
}
double getCylinderVolume(double radius, double height) {
return height*radius*radius*PI;
}
double getSampleVolume(double length, double height, double width) {
return length*height*width;
}
double calcPercentage(double length, double height, double width, int BubbleCount, double spBubbleRadius, int cylinderCount, double cyRadius, double cyHeight) {
double getSampleVolume(double, double, double);
double getCylinderVolume(double, double);
double getBubbleVolume(double);
return (BubbleCount*getBubbleVolume(spBubbleRadius) + cylinderCount*getCylinderVolume(cyRadius, cyHeight)) / getSampleVolume(length, height, width) * 100;
}
|