Function Overloading in C++

 #include<iostream>

using namespace std;

int sum(int a, int b){
    cout<<"by function1 is ";
    return a+b;
}

int sum(int a, int b, int c){
    cout<<"by function2 is ";
    return a+b+c;
}

int volume(int a){
    return a*a*a;
}

int volume(int r, int h){
    return 3.14*r*r*h;
}

int volume(int l, int b, int h){
    return l*b*h;
}

int main(){
    cout<<"the sum of 5 and 7 "<<sum(5, 7)<<endl;
    cout<<"the sum of 5, 7 and 57 "<<sum(5, 7, 57)<<endl;

    cout<<"the volume of cube of side length 5 is "<<volume(5)<<endl;
    cout<<"the volume of cylinder of radius 5 and height 7 is "<<volume(5, 7)<<endl;
    cout<<"the volume of cuboid of length 5, bredth 7 and height 57 units is "<<volume(5, 7, 57)<<endl;
   
    return 0;
}

Comments

Popular posts from this blog

oops recall, basic operations and nesting of member functions

OBJECT ORIENTED PROGRAMMING, classes public and private access modifiers (syntax)