Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Operationv2 {
  5.     int a;
  6.     int b;
  7.    
  8. public:
  9.     Operationv2( const int a, const int b )
  10.     : a(a), b(b) {}
  11.    
  12.     Operationv2()
  13.     : Operationv2( 0, 0 ) {}
  14.    
  15.     void swap( ) {
  16.         std::swap( a, b );
  17.     }
  18.  
  19.     friend istream & operator >> ( istream & is, Operationv2 & op ) {
  20.         is >> op.a >> op.b;
  21.         return is;
  22.     }  
  23.    
  24.     friend ostream & operator << ( ostream & os, const Operationv2 & op) {
  25.         os << "A = " << op.a << "\n"
  26.             << "B = " << op.b << std::endl;
  27.         return os;
  28.     }
  29.    
  30. };
  31.  
  32.  
  33. int main() {
  34.    
  35.     Operationv2 op;
  36.     cout << "Enter value for a and b" << std::endl;
  37.     cin >> op;
  38.     cout << op;
  39.     op.swap( );
  40.     cout << op;
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement