Answer to Question #263861 in C++ for Aashi

Question #263861

WAP to calculate and display the volume of sphere and cylinder



demonstrating the concept of function overloading

1
Expert's answer
2021-11-12T05:06:40-0500
#include<iostream>
#include<cmath>

using namespace std;

const double PI=3.141592;

double ShapeVolume(double rad);
double ShapeVolume(double rad, double heig);

int main()
{
	char ch;
	do
	{
		cout<<"\nPlease, select what you want to calculate: sphere (S or s),\n"
		<<"cylinder (C or c). Quit program (Q or q):";
		cin>>ch;
		if(ch=='S'||ch=='s')
		{
			double rad;
			cout<<"Please, enter the radius of sphere:";
			cin>>rad;
			cout<<"The volume of sphere is "
				<<ShapeVolume(rad);
		}
		else if(ch=='C'||ch=='c')
		{
			double rad, heig;
			cout<<"Please, enter the radius of cylinder:";
			cin>>rad;
			cout<<"Please, enter the heigh of cylinder:";
			cin>>heig;
			cout<<"The volume of cylinder is "
				<<ShapeVolume(rad,heig);
		}
	}
	while(ch!='Q'&&ch!='q');
}

double ShapeVolume(double rad)
{
	return ((4.0/3.0)*PI*pow(rad,3));
}
double ShapeVolume(double rad, double heig)
{
	return ((PI*pow(rad,2)*heig));
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS