Write a program to explain function overloading with type, order, and sequence of arguments.


Program Code:
#include<iostream>
using namespace std;
int sum(int,int);
int sum(int,int,int);
float sum(float,int,float);
double sum(double,float);
double sum(int,float,double);
long double sum(long double,double);
void main()
{
int a=sum(4,6);
int b=sum(2,4,6);
float c=sum(3.5f,7,5.6f);
double d=sum(7,8,1.2f);
double e=sum(1,2.2f,8.6);
long double f=sum(100,80);
clrscr();
cout<<"sum(int,int) ="<<a<<endl;
cout<<"sum(int,int,int) ="<<b<<endl;
cout<<"sum(float,int,float) ="<<c<<endl;
cout<<"sum(double,float) ="<<d<<endl;
cout<<"sum(int,float,double) ="<<e<<endl;
cout<<"sum(long double,double) ="<<f;
getch();
}
int sum(int x,int y)
{
return(x+y);
}
int sum(int x,int y,int z)
{
return(x+y+z);
}
float sum(float x,int y,float z)
{
return(x+y+z);
}
double sum(double x,float y)
{
return(x+y);
}
double sum(int x,float y,double z)
{
return(x+y);
}
long double sum(long double x,double y)
{
return(x+y);
}

Output:
sum(int,int) =10
sum(int,int,int) =12
sum(float,int,float) =16.1
sum(double,float) =9
sum(int,float,double) =11.8
sum(long,double,double) =180



Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: