You are on page 1of 3

Program No.

Aim:- Write a Program in C++ for Function Overloading.


Program:-
#include<iostream.h>
#include<conio.h>
void swap(char &x, char &y)
{
char t;
t = x;
x = y;
y = t;
}
void swap(int &x, int &y)
{
int t;
t = x;
x = y;
y = t;
}
void swap(float &x, float &y)
{
int t;
t=x;

SHRI VASANTRAO NAIK MAHAVIDHYALAYA, DHARNI Page 1


Program No. 8

x=y;
y=t;
}
void main()
{
clrscr();
char c1,c2;
cout<<"Enter two characters:"<<endl;
cin>>c1>>c2;
swap(c1,c2);
cout<<"On swapping c1,c2:"<<c1<<" "<<c2<<endl;
int a,b;
cout<<"Enter two integers(a,b)"<<endl;
cin>>a>>b;
swap(a,b);
cout<<"On swapping a,b:"<<a<<" "<<b<<endl;
float c,d;
cout<<"Enter two float(c,d):"<<endl;
cin>>c>>d;
swap(c,d);
cout<<"On swapping c,d:"<<c<<" "<<d<<endl;
getch();

SHRI VASANTRAO NAIK MAHAVIDHYALAYA, DHARNI Page 2


Program No. 8

}
---------------------------------------Output-----------------------------------
Enter two characters:
dD
On swapping c1,c2:D d
Enter two integers(a,b)
56 54
On swapping a,b:54 56
Enter two float(c,d):
5.43 7.88
On swapping c,d:7.88 5.43

SHRI VASANTRAO NAIK MAHAVIDHYALAYA, DHARNI Page 3

You might also like