Popular Posts

35.Write a program to show how the unary minus operator is overloaded .

35.Write a program to show how the unary minus operator is overloaded .

#include
#include
class space
{
int x;
int y;
int z;
public:
void getdata(int a,int b,int c);
void display(void);
void operator-();
};
void space:: getdata(int a,int b,int c)
{
x=a;
y=b;
z=c;
}
void space::display(void)
{
cout< cout< cout< }
void space::operator-()
{
x=-x;
y=-y;
z=-z;
}
int main()
{
clrscr();
space s;
s.getdata(10,-20,30);
cout<<"s: ";
s.display();
-s;
cout<<"s: ";
s.display();
getch();
return 0;
}

Output:

s: 10 -20 30
s: -10 20 -30

No comments: