The volume of a cylinder can be computed as: v = π * r * r * h Write a C++ function that computes the volume of a cylinder given r and h. Assume that the calling function passes the values of r and h by value and v by reference, i.e. v is declared in calling function and is passed by reference. The function just updates the volume v declared in calling function. The function prototype is given by: void vol_cyl(float r, float h, float& v); Write a main program that prompts the user to enter the values of r and h. It then calls the function vol_cyl to compute the value of volume and update its value in the main program. It then prints out the values of radius, height and volume on the screen.
#include <iostream>
using namespace std;
void vol_cyl(float r,float h,float &v)
{
v=3.14*r*r*h;
}
int main()
{
float v;
vol_cyl(2.3,4.5,v);
cout<<"volume is :"<<v;
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.