Friday 12 July 2013

Use of Function Overloading without Class in C++

1)

#include<iostream.h>
#include<conio.h>
int mul(int , int);
float add(float, float);
void main()
{
    int a,b,x;
    float c,d,y;
    clrscr();

    cout<<"\n Enter Two Integers: ";
    cin>>a>>b;
    x=mul(a,b);
    cout<<"\n Multiplication of two numbers= "<<x<<endl;

    cout<<"\n Enter Two Floating Numbers: ";
    cin>>c>>d;
    y=add(c,d);
    cout<<"\n Addition of Two Numbers= "<<y<<endl;
getch();
}
int mul(int m, int d)
{
    int tot;
    tot=m*d;
    return tot;
}
float add( float m, float d)
{
    float sum;
    sum=m+d;
    return sum;
}


Here is the output :::)

 
2)


#include<iostream.h>
#include<conio.h>
long add(long , long);
int mul(int, int);
float sub(float, float);
void main()
{
    long a,b,x;
    int c,d,y;
    float e,f,z;
    clrscr();
    cout<<"\n Enter two integers: ";
    cin>>a>>b;
    x=add(a,b);
    cout<<"\n Addion of two integers = "<<x<<endl;
    cout<<"\n Enter two integers: ";
    cin>>c>>d;
    y=mul(c,d);
    cout<<"\n Multiplication of two integers = "<<y<<endl;
    cout<<"\n ENter two floating numbers: ";
    cin>>e>>f;
    z=sub(e,f);
    cout<<"\n Subtraction of two numbers = "<<z<<endl;
getch();
}
long add(long m, long d)
{
    long sum;
    sum=m+d;
    return sum;
}
int mul(int m, int d)
{
    int sum;
    sum=m*d;
    return sum;
}
float sub(float m, float d)
{
    float sum;
    sum=m-d;
    return sum;
}

Here is the output :)))

 

No comments:

Post a Comment