SWAP TWO VARIABLES USING FUNCTIONS OVERLOADING

/*PROGRAM TO SWAP TWO VARIABLES USING FUNCTIONS HAVING SAME NAME BUT WITH DIFFERENT PARAMETERS*/

#include<conio.h>

#include<iostream.h>

class swap

{

int a,b;

float m,n,temp;

public:

void input();

void display(int,int);

void display(float,float);

};

void swap::input()

{

cout<<“Enter any two integers: “;

cin>>a>>b;

cout<<“Before swapping integer values are: a= “<<a<<” b= “<<b<<endl;

display(a,b);

cout<<“Enter any two float values: “;

cin>>m>>n;

cout<<“Before swapping float values are: m= “<<m<<” n= “<<n<<endl;

display(m,n);

}

void swap::display(int a,int b)

{

a=a+b;

b=a-b;

a=a-b;

cout<<“After swapping integer values are: a= “<<a<<” b= “<<b<<endl;

}

void swap::display(float m,float n)

{

temp=m;

m=n;

n=temp;

cout<<“After swapping float values are:  m= “<<m<<” n= “<<n;

}

 

void main()

{

swap s1;

clrscr();

s1.input();

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *