Part 1 Create three separate functions to find the surface and volume of each of
ID: 3806882 • Letter: P
Question
Part 1
Create three separate functions to find the surface and volume of each of the three different shapes. That is, one function to determine the surface area and volume of half sphere, one function to determine the surface area and volume of a rectangular cube and one function to find the surface area and volume of a cylinder. No flow chart is required for this part.
Part 2
Using what you have created in Part 1, create a main program that prompts the user for all of the required inputs, stores them in a vector and calls on the appropriate function and outputs the results to the command window. Create a flow chart for this program.
Explanation / Answer
code:
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
void half_sphere(double r) //4pir2
{
double vol =2*3.14*r*r/3;
double sa = 2*3.14*r*r;
cout<<"surface area of half sphere is: "<<sa<<endl;
cout<<"volume of half sphere is: "<<vol<<endl;
}
void rect_cube(double l,double w,double h)
{
double sa = 2*l*w + 2*l*h +2*h*w;
double vol = l*w*h;
cout<<"surface area of rectangular cube is: "<<sa<<endl;
cout<<"volume of half rectangular cube is: "<<vol<<endl;
}
void cylinder(double r,double h)
{
double sa = 2*3.14*r*h + 2*3.14*r*r;
double vol = 3.14 *r*r*h;
cout<<"surface area of cylinder is: "<<sa<<endl;
cout<<"volume of half cylinder cube is: "<<vol<<endl;
}
int main()
{
half_sphere(1);
rect_cube(1,1,1);
cylinder(1,1);
}
output:
mitali@Infoweave:~/Desktop/chegg$ ./a.out
surface area of half sphere is: 6.28
volume of half sphere is: 2.09333
surface area of rectangular cube is: 6
volume of half rectangular cube is: 1
surface area of cylinder is: 12.56
volume of half cylinder cube is: 3.14