You are on page 1of 2

Practical 18

XIII Exercise
18.1 Write a c++ program to interchange the values of two int,float and char using
function overloading.
INPUT:-
#include<iostream.h>
#include<conio.h>
class Swap1
{
public:
int no1,no2,temp1;
double no3,no4,temp2;
char a,b,temp3;
void swap(int a ,int b)
{
no1= a;
no2=b;
cout<<endl<<"int numbers befor swaping. ";
cout<<endl<<"number 1: "<<no1<<endl<<"number 2: "<<no2;
temp1=no1;
no1=no2;
no2=temp1;
}
void swap(double x,double y)
{
no3=x;
no4=y;
cout<<endl<<"floating numbers before swaping. ";
cout<<endl<<"floating no 1: "<<no3<<endl<<"floating no 2: "<<no4;
temp2=no3;
no3=no4;
no4=temp2;
}
void swap(char ch1,char ch2)
{
a=ch1;
b=ch2;
cout<<endl<<"charector value before swaping.";
cout<<endl<<"charector 1: "<<a<<endl<<"charector 2: "<<b;
temp3=a;
a=b;
b=temp3;
}
void show()
{
cout<<endl<<endl<<"values after swaping.";
cout<<endl<<"number 1 : "<<no1;
cout<<endl<<"number 2 : "<<no2;
cout<<endl<<"floating no 1: "<<no3;
cout<<endl<<"floating no 2: "<<no4;
cout<<endl<<"charector 1 : "<<a;
cout<<endl<<"charector 2 : "<<b;
}
};
void main()
{
clrscr();
cout<<"Output Prepared By Roll No=425 Omkar Shete."<<endl;
Swap1 s;
s.swap(5,3);
s.swap(4.25,5.6);
s.swap('t','p');
s.show();
getch();
}
OUTPUT:-

You might also like