Q-13: Write a C++ program that create a class and to perform swapping of two numbers without using third (temporary) variable.
        

Using - C++


#include<iostream> using namespace std; class Swapper { public: void Swap(int *a, int *b); }; void Swapper::Swap(int *a, int *b) { *a += *b; *b = *a - *b; *a = *a - *b; } int main() { int a, b; Swapper object; cout<< "Enter the value of a: "; cin>> a; cout<< "Enter the value of b: "; cin>> b; system("cls"); cout<< "Before Swapping: a = "<< a<< " & b = "<< b<< endl; object.Swap(&a,&b); cout<< "After Swapping : a = "<< a<< " & b = "<< b<< endl; return 0; }

OUTPUT

Enter the value of a:   100
Enter the value of b:   200 
-------------------------------------------------
Before Swapping:  a = 100   &   b = 200
After Swapping   :  a = 200   &   b = 100