/*
Swap two number using function overloading
*/
#include<iostream>
using namespace std;
void display(int a,int b);
void display(float a,float b);
void swap(int *a,int *b);
void swap(float *a,float *b);
int main()
{
int a=10,b=20;
float c=2.02,d=5.012;
cout<<"\n\n Before Swap: ";
display(a,b);
swap(&a,&b);
cout<<"\n\n After Swap: ";
display(a,b);
cout<<"\n\n Before Swap: ";
display(c,d);
swap(&c,&d);
cout<<"\n\n After Swap: ";
display(c,d);
return 0;
}
void display(int a,int b)
{
cout<<"\n\n A: "<<a;
cout<<"\n\n B: "<<b;
}
void display(float a,float b)
{
cout<<"\n\n A: "<<a;
cout<<"\n\n B: "<<b;
}
void swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
void swap(float *a,float *b)
{
float temp;
temp=*a;
*a=*b;
*b=temp;
}
Swap two number using function overloading
*/
#include<iostream>
using namespace std;
void display(int a,int b);
void display(float a,float b);
void swap(int *a,int *b);
void swap(float *a,float *b);
int main()
{
int a=10,b=20;
float c=2.02,d=5.012;
cout<<"\n\n Before Swap: ";
display(a,b);
swap(&a,&b);
cout<<"\n\n After Swap: ";
display(a,b);
cout<<"\n\n Before Swap: ";
display(c,d);
swap(&c,&d);
cout<<"\n\n After Swap: ";
display(c,d);
return 0;
}
void display(int a,int b)
{
cout<<"\n\n A: "<<a;
cout<<"\n\n B: "<<b;
}
void display(float a,float b)
{
cout<<"\n\n A: "<<a;
cout<<"\n\n B: "<<b;
}
void swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
void swap(float *a,float *b)
{
float temp;
temp=*a;
*a=*b;
*b=temp;
}