Untitled
unknown
plain_text
3 years ago
1.1 kB
3
Indexable
#include<iostream>
#include<string>
using namespace std;
class SWAP{
public:
int a;
int b;
void swap_value(int a, int b)
{
int temp=a;
a=b;
b=temp;
}
void swap_reference(int &a, int &b)
{
int temp=a;
a=b;
b=temp;
}
};
int main(){
int a;
cout<<"Enter a: ";
cin>>a;
int b;
cout<<"Enter b: ";
cin>>b;
int ch;
cout<<"SELECT SWAP CHOICE"<<endl<<"1. 1 for Call by Value" << endl <<"2. 2 for Call by Reference"<<endl;
cout<<"Enter Choice: ";
cin>>ch;
SWAP obj;
switch(ch)
{
case 1:
cout<<" Call by Value "<<endl;
obj.swap_value(a,b);
break;
case 2:
cout<<"Call by Reference "<<endl;
obj.swap_reference(a,b);
break;
default:
cout<<"WRONG CHOICE"<<endl;
}
cout<<"a: "<<a<<endl;
cout<<"b: "<<b;
}
Editor is loading...