10. Consider following class Numbers Class Numbers { int x,y,z; public: // methods }; Overload the operator unary minus- to negate the numbers.


#include<iostream.h>
#include<conio.h>
class number
{
int x,y,z;
public:
void get()
{
cout<<“\nEnter Three number: \n”;
cin>>x>>y>>z;
}
void disp()
{
cout<<“\n\n”<<x<<“\t”<<y<<“\t”<<z;
}
void operator-()
{
x=-x;
y=-y;
z=-z;
}
};
void main()
{
number n;
clrscr();
n.get();
cout<<“\n\nNumber is “;
n.disp();
-n;
cout<<“\n\nNegated number: “;
n.disp();
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s