OOPc using C++

With this blog I want to share my knowledge of OOPs and C++. I Hope this can quench your thirst for learning.Any suggestions and comments are welcome.

Wednesday, August 4, 2010

Program 5- Program to demonstrate Function Overloading.

The program returns the absolute value of an argument.

#include<iostream.h>
void main( )
{
        int i=-25,j;
        long l=-100000L,m;
        double d=-12.34,e;
        int abs(int);
        long abs(long);
        double abs(double);


        j=abs(i);
        m=abs(l);
        e=abs(d);


        cout<<endl<<j<<endl<<m<<e;
}


int abs(int ii)
{
         return(ii>0?ii:ii*-1);
}
long abs(long ll)
{
         return(ll>0?ll:ll*-1);
}
double abs(double dd)
{
         return(dd>0?dd:dd*-1);
}


Click here to read about Function Overloading


      

No comments:

Post a Comment