Write a C++ program to calculate the volume of the cube, cylinder and rectangular box using function overloading.
The algorithm to solve the above problem:
STEP 1: Start the program
STEP 2: Declare s, h, b as integer, r as double and l as long
STEP 3: Initialize the values for s, h, b, r and l
STEP 4: Call the function with three arguments for cube passed to it.
STEP 5: Call the function with three arguments for cylinder passed to it.
STEP 6: Call the function with three arguments for rectangular box passed to it.
STEP 7: Return the values to the called function to the calling function
STEP 8: Write the value in the main program
STEP 9: Terminate the program.
Implementation of above problem using C++ :
#include<iostream>
using namespace std;
int volume(int);
double volume(double,int);
long volume(long,int,int);
int main()
{
cout<<volume(30)<<"\n";
cout<<volume(10, 15)<<"\n";
cout<<volume(1501,50,20)<<"\n";
return 0;
}
int volume(int s)
{
return(s*s*s);
}
double volume(double r,int h)
{
return(3.14*r*r*h);
}
long volume(long l,int b,int h)
{
return(l*b*h);
}
The output of above program is tested on www.jdoodle.com
Output:
27000
4710
1501000
Thanks
Mukesh Rajput
Post A Comment:
0 comments: