Write a C++ program to create a class Integer. Write necessary member functions to overload the operator unary pre and post increment ‘++’ for an integer number.

//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;

#include<iostream.h>
#include<conio.h>
class integer
{
   int a,b;
public:
   void acc(int x,int y)
   {
    a=x;
        b=y;
   }
   void operator +() //function overloading
   {
    a++;
       ++b;
   }
   void dis()
   {
    cout<<"\n   a\t: "<<a;
      cout<<"\n   b\t: "<<b<<"\n";
   }
};
void main()
{
   int a,b;
   cout<<"\nEnter Value of a:- ";
   cin>>a;
   cout<<"\nEnter Value of b:- ";
   cin>>b;
   integer i; //object created
   i.acc(a,b);
   cout<<"\n=======before========= "<<endl;
   i.dis();
   + i;
   cout<<"\n=======after========== "<<endl;
   i.dis();
   getch();
}

0 Comments