SHARE
TWEET

Untitled

a guest Aug 23rd, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Operationv1 {
  5.     int a;
  6.     int b;
  7.    
  8. public:
  9.     Operationv1( int x, int y ) {
  10.         a = x;
  11.         b = y;
  12.     }
  13.    
  14.     void display() {
  15.         cout << "A = " << a << "\n"
  16.             << "B = " << b << std::endl;
  17.     }
  18.    
  19.     void swap( ) {
  20.         std::swap( a, b );
  21.         // or
  22.         // int t = a; a = b; b = t;
  23.     }
  24.    
  25. };
  26.  
  27.  
  28. int main() {
  29.    
  30.     int a, b;
  31.     cout << "Enter value for a and b" << std::endl;
  32.     cin >> a >> b;
  33.    
  34.     Operationv1 op( a, b );
  35.     op.display( );
  36.     op.swap( );
  37.     op.display( );
  38.     return 0;
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top