as

Write a C++ program to demonstrate for Operator Overloading

Program for Operator Overloading.  



Code :-
/**********************Programe for Oeprator Overloading********************/
# include<iostream.h>
# include<conio.h>
class xyz
{
                int a,b;
                public:
                void getdata()
                {
                                cout<<"\nEnter the value of a&b";
                                cin>>a>>b;
                }
                void putdata()
                {
                                 cout<<a<<""<<b;
                }
                void operator++();
                void operator--();
};
void xyz::operator++()
{
                ++a;
                ++b;
}
void xyz::operator--()
{
                --a;
                --b;
}
void main()
{
                clrscr();
                xyz x1,x2;
                x1.getdata();
                cout<<"\nValue of a&b in x1:";
                x1.putdata();
                ++x1;
                cout<<"\nNew Value of a&b in x1:";
                x1.putdata();
                x2.getdata();
                cout<<"\nValue of a&b in x2:";
                x2.putdata();
                --x2;
                cout<<"\nNew value of a&b in x2:";
                x2.putdata();
                getch();
}
/******************** OUT PUT*****************
 Enter the value of a&b 11 12
 Value of a&b in x1:11 12
 New Value of a&b in x1:12 13
 Enter the value of a&b 10 14
 Value of a&b in x2:10 14
 New value of a&b in x2:9 13
******************** OUT PUT*****************/
Output :-

 Enter the value of a&b 11 12
 Value of a&b in x1:11 12
 New Value of a&b in x1:12 13
 Enter the value of a&b 10 14
 Value of a&b in x2:10 14
 New value of a&b in x2:9 13