QUE– IMPLEMENT THE LOGIC FOR OPERATOR OVERLOADING AS WELL AS POST INCREMENT AND PRE INCREMENT
ANS–
#include<iostream>
#include<conio.h>
using namespace std;
class Inc
{
private:
int count ;
public:
Inc()
{
count = 0 ;
}
Inc(int C)
{
count = C ;
}
Inc operator ++ () //for pre-increment
{
count=count+2; //we can give output whatever we want
}
Inc operator ++ (int) //for post-increment with argument
{
count=count+4;
}
Inc operator – – () //for pre- decrement
{
count=count-2; //we will use here any expression
}
Inc operator – – (int) //for post-decrement
{
count=count-4;
}
void display(void)
{
cout << count << endl ;
}
};
int main()
{
Inc a, b(6), c, d, e(2), f(9);
cout << “Before using the operator ++()\n”;
cout << “a = “;
a.display();
cout << “b = “;
b.display();
++a;
b++;
cout << “After using the operator ++()\n”;
cout << “a = “;
a.display();
cout << “b = “;
b.display();
c = ++a;
d = b++;
cout << “Result prefix (on a) and postfix (on b)\n”;
cout << “c = “;
c.display();
cout << “d = “;
d.display();
cout << “Before using the operator –()\n”;
cout << “e = “;
e.display();
cout << “f = “;
f.display();
– -e;
f- -;
cout << “After using the operator –()\n”;
cout << “e = “;
e.display();
cout << “f = “;
f.display();
cout<<“\n\nPROGRAMMING AT C#ODE STUDIO”;
getch();
return 0;
}