Your Ad Here

Sunday, June 1, 2008

OPERATOR OVERLOADING - Unary

/********* IMPLEMENTATION OF OPERATOR OVERLOADING (UNARY)*********/
#include< iostream.h>
#include< conio.h>

class unary
{
private:
int x,y,z;
public:

unary(void)
{
cout< < "Enter Any Three Integer Nos. : ";
cin>>x>>y>>z;
}

void display(void)
{
cout< < endl< < " The Three Nos. Are : "< < x< < " , "< < y< < " , "< < z;
}

void operator --()
{
x = --x;
y = --y;
z = --z;
}

void operator ++()
{
x = ++x;
y = ++y;
z = ++z;
}
};

void main()
{
clrscr();
unary s;
s.display();

--s;
cout< < endl< < endl< < endl< < "******* The Decremented Values ********"< < endl;
s.display();

++s;
cout< < endl< < endl< < endl< < "******* The Incremented Values ********"< < endl;
s.display();
cout< < endl< < endl< < "***************************************";

getch();
}



/************ OUTPUT **************
Enter Any Three Integer Nos. : 4
-8
6

The Three Nos. Are : 4 , -8 , 6


******* The Decremented Values ********

The Three Nos. Are : 3 , -9 , 5


******* The Incremented Values ********

The Three Nos. Are : 4 , -8 , 6

***************************************
*/

3 comments:

SatnamGill said...

best program

Anonymous said...

Hello there,

Thanks for sharing the link - but unfortunately it seems to be down? Does anybody here at cppgm.blogspot.com have a mirror or another source?


Thanks,
Daniel

Anonymous said...

Thanks Anna... Very useful link...

Your Ad Here