Function Overloading for Volume Calculation C++ Programming
Solutions:
#include<iostream> #include<math.h> using namespace std; void vol(float); void vol(float,float,float); void vol(float,float); int main() { int br=0; while(br!=4) { cout<<"\n****Choose The Following Options****\n"; cout<<"-Press 1 for Cube Volume\n"; cout<<"-Press 2 for Rectangular Prism Volume\n"; cout<<"-Press 3 for Cylinder Volume "<<endl; cout<<"-Press 4 for Exit"<<endl; cin>>br; switch(br) { case 1:cout<<"Enter Side of the Cube"<<endl; float s; cin>>s; vol(s); break; case 2:cout<<"Enter Value of radius followed by height"<<endl; float r,h; cin>>r>>h; vol(r,h); break; case 3:cout<<"Enter Value of width breath height for Rectangular Prism:"<<endl; float a,b,c; cin>>a>>b>>c; vol(a,b,c); break; default:cout<<"\n Invalid Choice....!\n"; break; } } return 0; } void vol(float a) { cout<<"Cube Volume is:"<<a*a*a<<endl; } void vol(float r,float h) { float pi=3.14; cout<<"Cylinder Volume is:"<<(pi*pow(r,2)*h)<<endl; } void vol(float a,float b,float c) { cout<<"Rectangular Prism Volume is:"<<a*b*c<<endl; }
0 comments:
Post a Comment