Answer to Question #295665 in C++ for Varsha Chouhan

Question #295665

Write volume function which calculates the volume of sphere rectangle and cylinder using function overloading

1
Expert's answer
2022-02-09T09:24:59-0500
#include <iostream>
#include <string>
using namespace std;




float calculateVolume(float radius){
	return (4*3.14*radius*radius*radius)/3;
}


float calculateVolume(float side1,float side2,float side3){
	return side1*side2*side3;
}


float calculateVolume(float radius,float height){
	return 3.14*radius*radius*height;
}






int main() {
	float radius;
	float side1,side2,side3;
	float height,volume;
	cout<<"Enter the radius of sphere: ";
	cin>>radius;
	cout<<"Volume of Sphere = "<<calculateVolume(radius)<<"\n\n";


	
	cout<<"Enter Side 1 of Rectangular Prism: ";
	cin>>side1;
	cout<<"Enter Side 2 of Rectangular Prism: ";
	cin>>side2;
	cout<<"Enter Side 3 of Rectangular Prism: ";
	cin>>side3;


	cout<<"Volume of Rectangular Prism = "<<calculateVolume(side1,side2,side3)<<"\n\n";


	cout<<"Enter Radius of Cylinder: ";
	cin>>radius;
	cout<<"Enter Height of Cylinder:";
	cin>>height;
	cout<<"Volume of Cylinder is: " <<calculateVolume(radius,height)<<"\n\n";




	system("pause");
	return 0;
}

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