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

The question looks long but should be pretty simple. Please help!! It needs to b

ID: 3804822 • Letter: T

Question

The question looks long but should be pretty simple. Please help!! It needs to be done in C++.

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.

For example, the message may be something like “The height of the sample must be greater than zero.

Please re-enter the height of the sample.” or “The radius of the bubbles must be greater than zero.

Please re-enter the radius of the bubbles.”

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 Programming Project 3 2 CMPSC 201 – Spring 2016 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).

For example you error message should be something like “The number of spherical bubbles must be greater than or equal to 0. Please re-enter the number of spherical bubbles.”

• A value-returning function will accept the radius of a sphere then calculate and return the volume of a sphere (vol = 4/3r 3 ).

• A value-returning function that will accept the radius and height of a cylinder, then calculate and return the volume of a cylinder (vol = r 2 h).

• 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 smple, 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. Make sure you use appropriate data types and that your submission follows the assignment guidelines posted on ANGEL. The value of pi should be declared as a constant of 3.14159.

Three example outputs are given below Please remember to follow the assignment guidelines for the course (posted on ANGEL. For example, 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. In addition to the introductory comments for the program your code should contain comments for each function other than main that states the purpose of the function, input Programming Project 3 3 CMPSC 201 – Spring 2016 to the function (both input from the function call and interactive input), output from the function (both information sent back to the function call and interactive output), and processing performed in the function. These comments should be placed immediately before the function definition.

Example 1: (user’s input is shown in bold)

Enter the height, length, and width of the sample in centimeters. 25.8 40.67 35.5

How many spherical bubbles are present? 10

What is the radius of the spherical bubbles in centimeters? 1.2

How many cylindrical pores are present? 8

What are the radius and height of the cylindrical pores in centimeters? 0.8 4

The material contains 0.367 % air.

Example 2: (user’s input is shown in bold)

Enter the height, length, and width of the sample in centimeters. -3 28 56.5

The height of the sample must be greater than zero.

Please re-enter the height of the sample. -4.5

The height of the sample must be greater than zero.

Please re-enter the height of the sample. 25

How many spherical bubbles are present? -50

The number of spherical bubbles must be greater than or equal to 0.

Please re-enter the number of spherical bubbles. 50

What is the radius of the spherical bubbles in centimeters? 0.9

How many cylindrical pores are present? 20

What are the radius and height of the cylindrical pores in centimeters? 1 -2.5

The height of the cylindrical pores must be greater than 0.

Please re-enter the height of the cylindrical pores. 1.5

The material contains 0.624 % air.

Following the guidlines properly would be highly appreciated. Thank you.

Explanation / Answer

Not to have function definitions on main.create .h file and place the definition and create a CPP file with main

Her I have given the function declaration above main and definition below the main method.

Please cross check with the percentage calculation formula.Apart from that the code is working 100%.the percentage value is near value as given in the sample output.

#include <iostream>

#include<cstring>

#include<math.h>

#define PI 3.14159

using namespace std;

void validate(float &,string);

int validate(int ,string);

float volSphr(float );

float volCylndr(float ,float );

float volPipe(float ,float ,float );

float calPrcnt(float ,float ,float ,int ,float ,int ,float ,float );

int main(){

float ph,pl,pw,rsphere,rcylinder,hcylinder;

int nb,nc,bubbles_num,cylinders_num;

string sample_height="The height of the sample ";

string sample_length="The length of the sample ";

string sample_width="The width of the sample ";

string bubble_radius="the radius of the spherical bubbles ";

string no_bubbles="The number of spherical bubbles ";

string no_cylinders="The number of surface of cylinderical pores ";

string radius_cylinder="The radius of the cylindrical pores ";

string height_cylinder="The height of the cylindrical pores ";

cout<<"Enter the height,lenght and width of the sample in centimeters ";

cin>>ph>>pl>>pw;

validate(ph,sample_height);

validate(pl,sample_length);

validate(pw,sample_width);

//cout<<"Values of height , length and width are : "<<h<<" "<<l<<<<" "<<w<<" ";

cout<<" How many spherical bubbles are present ?";

cin>>nb;

bubbles_num=validate(nb,no_bubbles);

cout<<" What is the radius of the spherical bubbles in centimeters?";

cin>>rsphere;

validate(rsphere,bubble_radius);

cout<<" How many cylindrical pores are present?";

cin>>nc;

cylinders_num=validate(nc,no_cylinders);

cout<<" What are the radius and height of cylindrical pores in centimeters?";

cin>>rcylinder>>hcylinder;

validate(rcylinder,radius_cylinder);

validate(hcylinder,height_cylinder);

//cout<<"The number of spherical bubbles and no of surface cylinders "<<bubbles_num<<" "<<cylinders_num<<" ";

float prcnt=calPrcnt( pw, pl, ph, bubbles_num, rsphere, cylinders_num, rcylinder, hcylinder);

cout<<" Percantage of air is "<<floor(prcnt * 1000) / 1000<<"% air ";

return 0;

}

void validate(float &value,string str){ //void function to validate inputs

while(value<=0){

cout<<str<<" must be greater than zero. Please re-enter "<<str; //if invalid user to input till valide

cin>>value;}

}

int validate(int count,string str1){ //validate function with 1 return value

while(count<0){

cout<<str1<<" must be greater than or equal 0. Please re-enter "<<str1;

cin>>count;}

return count;

}

float volSphr(float rsphere){ //volume of sphere

return (4/3)*PI*rsphere*rsphere*rsphere;}

float volCylndr(float rcylinder,float hcylinder){ //volume of cylindrical pores

return PI*rcylinder*rcylinder*hcylinder;}

float volPipe(float ph,float pl,float pw){ //volume of rectangle parallael piped

return ph*pl*pw;}

float calPrcnt(float pw,float pl,float ph,int bubbles_num,float rsphere,int cylinders_num,float rcylinder,float hcylinder){ //calculate percentage

float spherevol=bubbles_num*volSphr(rsphere);

float cylndrvol=cylinders_num*volCylndr(rcylinder,hcylinder);

float Rectpipevol=volPipe(ph,pl,pw);

float percentage=(spherevol+cylndrvol)/Rectpipevol*100;

return percentage;

}

/*25.8 40.67 35.5

10

1.2

8

0.8 4*/

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