SWAPPING OF TWO NUMBERS

#include
#include
class swap
{
int a,b,t;
public:
void value(int,int);
void ref(int&,int&);
void addr(int*,int*);
};
void swap::value(int a,int b)
{
cout<<"enter the numbers to be swapped";
cin>>a;
cin>>b;
int t;
t=a;
a=b;
b=t;
cout<<"\n The numbers after swapping are \n "<}
void swap::ref(int &a,int &b)
{
cout<<"enter the numbers to be swapped";
cin>>a;
cin>>b;
int t;
t=a;
a=b;
b=t;
cout<<"\n The numbers after swapping are \n"<}
void swap::addr(int *a,int *b)
{
cout<<"enter the numbers to be swapped";
cin>>*a;
cin>>*b;
int t;
t=*a;
*a=*b;
*b=t;
cout<<"\n The numbers after swapping are \n"<<*a<<"\t"<<*b;
}
void main()
{
int a,b,opt;
swap sp;
clrscr();
do
{
cout<<"\n\n\tMENU\n";
cout<<"\t--------\n";
cout<<"1.pass by value\n2.pass by reference\n3.Pass by address \n4.exit\n";
cout<<"enter the option\n";
cin>>opt;
switch(opt)
{
case 1:sp.value(a,b);
break;
case 2:sp.ref(a,b);
break;
case 3:sp.addr(&a,&b);
break;
case 4:break;
}
}
while(opt!=4);
getch();
}

Comments