C++ Program For Pre Increment and Decrement Operator Overloading

Free C++ course with real-time projects Start Now!!

Program 1

//Unary Operator overloading (- operator)
#include<iostream>
#define clrscr() system("cls")
using namespace std;
class Test
{
      int a,b,c;
      public:
      Test(int a,int b,int c)
      {
        this->a=a;
        this->b=b;
        this->c=c;
      }
      void display();
      void operator++();
      void operator--();
     
};
void Test::operator++()
{
    ++a;
    ++b;
    ++c;
}
void Test::operator--()
{
    --a;
    --b;
    --c;
}
 void Test::display()
      {
        cout<<"\n"<<a <<"  "<<b<<"  "<<c;
      }
int main()
{
    clrscr();
    Test T1(10,20,30);
    T1.display();
    cout<<endl;
    ++T1;  //T1.operator++()
    //--T1;  //T1.operator--()
    
    T1.display();
     
    return 0;
}

 

Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *