upsidedown

inc dec ovrld r.p

Mar 9th, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include<iostream.h>
  2.  
  3. class opr
  4. {
  5.     int c;
  6. public:
  7.     opr()
  8.     {
  9.         c=0;
  10.     }
  11.  
  12.     opr(int a)
  13.     {
  14.         c=a;
  15.     }
  16.  
  17.     void operator++()
  18.     {
  19.         c=c+1;
  20.     }
  21.  
  22.     void operator--()
  23.     {
  24.         c=c-1;
  25.     }
  26.  
  27.     void display()
  28.     {
  29.         cout<<c<<"\n";
  30.     }
  31. };
  32.  
  33. int main()
  34. {
  35.     int x;
  36.     opr s1;
  37.     cout<<"enter a number:\n";
  38.     cin>>x;
  39.     s1=opr(x);
  40.     ++s1;
  41.     cout<<"after incrementing ";
  42.     s1.display();
  43.     --s1;
  44.     cout<<"after decrementing ";
  45.     s1.display();
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment