Write in C++ Code. Goals: Developing problem-solving skills and functions Proble
ID: 3864001 • Letter: W
Question
Write in C++ Code.
Goals: Developing problem-solving skills and functions
Problem: You will create a program that will approximate the volume of pores in a new composite material. While the material is being formed it is injected with air which creates bubble and pores to decrease the density of the composite material. However, if too many pores and bubbles are created, the material loses its strength and catastrophic failure occurs. You are to create a program that will determine what percentage of the material is due to pores (connected to the surface) and bubbles (totally enclosed within the sample). For the purposes of this analysis all bubbles will be assumed to be the same size and all the pores will be cylinders of the same size.
The sample that is being analyzed is a rectangular parallelepiped (all angles are 90 degrees, but length, width, and height may be different values). The user will be prompted to enter the dimensions of the sample (height, length, and width), the number of the bubbles, the radius of the bubbles, the number of cylindrical pores, the radius of the cylindrical pores and the height of the cylindrical pores.
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 two parameters: the dimension and what the dimension corresponds to e.g. “the height of the sample”, “the radius of spherical bubble”, etc.(see examples below). This function should contain a single loop and no selection structures. If the dimension is incorrect, the user should be told what dimension is incorrect and prompt the user to re-enter the value for the dimension.
The check should be robust (i.e. the user will be given the error message and prompted to re-enter the incorrect value as long as it is invalid.
• A value-returning function that will robustly confirm that the value entered for the number of spherical bubbles or cylindrical pores is greater than or equal zero. This function should accept two parameters: the value and what the value corresponds to i.e. number of spherical bubbles or number of surface cylinders. This function should contain a single loop and no selection structures. If the value is incorrect, tell the user should be told what value (number of spherical bubbles or number of cylindrical pores) is incorrect and prompt the user to re-enter the number. (You may assume that the number will be a whole number
• A value-returning function will accept the radius of a sphere then calculate and return the volume of a sphere (vol = 4/3r3).
• A value-returning function that will accept the radius and height of a cylinder, then calculate and return the volume of a cylinder (vol = r2h).
• A value-returning function that accept the height, length, and width of a rectangular parallelepiped then calculate and return the volume of the rectangular parallelepiped (vol = hlw).
• A value-returning function that will accept 8 parameters: width, length, and height of the parallelepiped sample; 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, then calculate the percent of the sample that is air (combination of spherical bubbles and cylindrical pores). The percentage should be returned to the function call.
Your main function should ask the user to input the dimensions of the parallelepiped sample, 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 valid. After this confirmation, the function to determine the percentage of air present should be called. Then the main function should output the percentage of air present. The percentage of air should be output using 3 significant digits. You may assume that the total volume of spherical bubbles and cylindrical pores will not exceed the volume of the original sample.
The value of pi should be declared as a constant of 3.14159.
Do not use global variables, do not use break statements in loops, do not use more than one return statement per function, do not put functions definitions before main, etc.
Explanation / Answer
#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, br, ht, spRad, cyRad, cyHt, perct;
int cSp, cCy;
cout<<"Enter length of Parallelepiped: ";
cin>>len;
dimChecker(&len, "length of Parallelepiped");
cout<<"Enter breadth of Parallelepiped: ";
cin>>br;
dimChecker(&br, "breadth of Parallelepiped");
cout<<"Enter height of Parallelepiped: ";
cin>>ht;
dimChecker(&ht, "height of Parallelepiped");
cout<<"Enter radius of Sphere: ";
cin>>spRad;
dimChecker(&spRad, "radius of sphere");
cout<<"Enter count of Sphere: ";
cin>>cSp;
cSp = countChecker(cSp, "count of Spheres");
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>>cSp;
cSp = countChecker(cSp, "count of Cylinders");
perct = calcPercentage(len,br,ht,cSp,spRad,cCy,cyRad,cyHt);
if (perct<1)
cout << fixed << setprecision(3);
else if (perct<10)
cout << fixed << setprecision(2);
else
cout << fixed << setprecision(1);
cout<<perct;
}
void dimChecker(double *dim, char *param) {
while(*dim <= 0) {
cout<<"Dimention of "<<param<<" is not more than zero, please re enter. ";
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. ";
cin>>count;
}
return count;
}
double getSphereVolume(double radius) {
return radius*radius*radius*4*PI/3;
}
double getCylinderVolume(double radius, double height) {
return height*radius*radius*PI;
}
double getParallelepipedVolume(double length, double height, double width) {
return length*height*width;
}
double calcPercentage (double length, double height, double width, int sphereCount, double spRadius, int cylinderCount, double cyRadius, double cyHeight) {
double getParallelepipedVolume(double, double, double);
double getCylinderVolume(double, double);
double getSphereVolume(double);
return (sphereCount*getSphereVolume(spRadius) + cylinderCount*getCylinderVolume(cyRadius, cyHeight))/getParallelepipedVolume(length, height, width)*100;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.