0% found this document useful (0 votes)
38 views3 pages

Program No 8 (1) HG

The document demonstrates function overloading in C++ by defining multiple swap functions that take different data types as parameters and swapping their values. It defines swap functions for char, int and float, calls each in turn to swap variables of the given types and displays the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views3 pages

Program No 8 (1) HG

The document demonstrates function overloading in C++ by defining multiple swap functions that take different data types as parameters and swapping their values. It defines swap functions for char, int and float, calls each in turn to swap variables of the given types and displays the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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