Write a program to overload unary (++) operator and unary (--) operator.
#include<iostream>
using namespace std;
class Unary
{
    int x, y;
 public:
    void input()
    {
        cout<<"Input two intergers: \n";
        cin>>x>>y;
    }
    void operator--()
    {
        x--;
        y--;
    }
    void operator++()
    {
        x++;
        y++;
    }
    void show()
    {
        cout<<"\nX : "<<x;
        cout<<"\nY : "<<y;
    }
};
int main()
{
    Unary U;
    U.input();
    --U;
    cout<<"\nAfter Decrement: ";
    U.show();
    ++U;
    ++U;
    cout<<"\n\nAfter Increment: ";
    U.show();
    return 0;
}
Comments