2. Calculate the volume of a spherical bottom flask pictured below. Consider the
ID: 3746723 • Letter: 2
Question
2. Calculate the volume of a spherical bottom flask pictured below. Consider the bottom to be a partially filled sphere and the top part to be a cylinder. Define PI as a constant (either as a symbolic constant or declared as a constant). In function main prompt the user for the radius of the spherical portion (R), and the radius (r) and height (h) of the cylindrical portion. Use data type double for all variables. Calculate the angle theta using the inverse sine function. Then calculate volumes of the spherical portion, the cylindrical portion, and the total volume. Use the following formulas Volume of cylinder: v = r,h Volume of partially filled sphere: Print the individual volumes and total volume with two digits after the decimal point. Test with values R 5 cm, r 2 cm, and h 8 cm. R12(1 + cose)+-cos (1-cos2 ) VExplanation / Answer
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
#define PI 3.1415926
int main()
{
double r, R, h, angle, volCyl, volSph, totalVol,temp;
cout<<"Enter radius of Sphere ";
cin>>R;
cout<<"Enter radius of Cylinder ";
cin>>r;
cout<<"Enter Height of Cylinder ";
cin>>h;
angle = (asin(r/R));
temp = cos(angle);
volCyl = PI*r*r*h;
volSph = PI*R*R*R;
volSph = volSph * ((2*(1+temp))/3 + ((1*temp)/3)*(1-pow(temp,2)));
totalVol = volCyl + volSph;
std::cout <<std::setprecision(2) << std::fixed;
cout<<"Volume of Cylinder: "<<volCyl<<endl;
cout<<"Volume of Sphere: "<<volSph<<endl;
cout<<"Total Volume: "<<totalVol<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.