FUNCTIONAL OVERLOADING


SOURCE CODE:
#include<iostream.h>
#include<conio.h>
void swap(int x,int y)
{
  int temp;
  cout<<"\n Before swapping of two Intger values:\t"<<x<<"\t "<<y;
  temp=x;
  x=y;
  y=temp;
  cout<<"\n After swapping of two Intger values:\t"<<x<<"\t "<<y;
}
void swap(float x,float y)
{
  float temp;
  cout<<"\n Before swapping of two Float values:\t"<<x<<"\t "<<y;
  temp=x;
  x=y;
  y=temp;
  cout<<"\n After swapping of two Float values:\t"<<x<<"\t "<<y;
}
void swap(char x,char y)
{
  char temp;
  cout<<"\n Before swapping of two Characters:\t"<<x<<"\t "<<y;
  temp=x;
  x=y;
  y=temp;
  cout<<"\n After swapping of two Characters:\t"<<x<<"\t "<<y;
}
void main()
{
  int a,b;
  float c,d;
  char e,f;
  clrscr();
  cout<<"\n\n Enter two integer values:\t";
  cin>>a>>b;
  swap(a,b);
  cout<<"\n\n Enter two float values:\t";
  cin>>c>>d;
  swap(c,d);
  cout<<"\n\n Enter two characters:\t";
  cin>>e>>f;
  swap(e,f);
  getch();
}

OUTPUT:

 Enter two integer values:      10      20

 Before swapping of two Integer values:   10       20
 After swapping of two Integer values:     20       10

 Enter two float values:        10.25   20.25

 Before swapping of two Float values:   10.25    20.25
 After swapping of two Float values:      20.25    10.25

 Enter two characters:  A       z

 Before swapping of two Characters:     A        z
 After swapping of two Characters:        z        A
Previous
Next Post »

Still not found what you are looking for? Try again here.