overloading unary operators using friend


Overloading Unary Operators Using Friend Function

class sign

{

int a,b,c;

public:

sign(){}; sign(int,int,int); void putdata(void);

friend void operator-(sign &);

};

void operator-(sign &s)

{s.a=-s.a;s.b=-s.b;s.c=-s.c;        }

void sign::putdata(void)

{cout<<"a is: "<<a<<"\n"; cout<<"b is "<"\n"; cout<<"c is "<<c<<"\n";

}

sign::sign(int x,int y, int z)

{a=x;b=y;c=z;                         }

int main()

{sign s; //Implicit constructor calling s=sign(1000,2,10); //Explicit constructor calling s.putdata();

-s;

s.putdata();

cout<<endl;

s=sign(-2000,2,-5);

s.putdata();

-s;

s.putdata();

return 0;

}

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: overloading unary operators using friend
Reference No:- TGS0161153

Expected delivery within 24 Hours