WAP to calculate and display the surface area of sphere and cylinder demonstrating the concept of function overloading
#include<iostream>
#include<math.h>
using namespace std;
double pi=3.1415;
double volume(double r){
double vol = (4/3) * pi * r * r* r;
return vol;
}
double volume(double h, double r){
double vol = pi * r * r * h;
return vol;
}
int main(){
cout<<"Enter the radius of the sphere:\n";
double rad;
cin>>rad;
cout<<"The volume of the sphere is :"<<volume(rad)<<endl;
cout<<"Enter the radius of the cylinder\n";
double r;
cin>>r;
cout<<"The height of the cylinder\n";
double h;
cin>>h;
cout<<"The volume of the cylinder is :"<<volume(h,r)<<endl;
}
Comments
Leave a comment