Overloading unary operators using friend function, C/C++ Programming

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;

}

Posted Date: 9/20/2012 8:18:47 AM | Location : United States







Related Discussions:- Overloading unary operators using friend function, Assignment Help, Ask Question on Overloading unary operators using friend function, Get Answer, Expert's Help, Overloading unary operators using friend function Discussions

Write discussion on Overloading unary operators using friend function
Your posts are moderated
Related Questions
how to make a program this struct items/product

Hello I''m new to programming, and I''m making now my 1st program. My question is how to put substr in textbox that question mark should be at the end of sentence? And 2nd question

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

you are to create a text adventure game that uses pointers. You have a rich, eccentric Uncle Billy who is soon to be deceased. How soon.....oops......he''s gone. He has left yo

.Develop a two dimensional interactive game with the following features: 1. Use OpenGL (any version you find convenient) 2. The game can either be two player or one player with the

Q:  Tells the operators one can override; which operators should he override? A: Bottom line: don't puzzle your users. Remember the reason of operator overloading: to decreas

solve mesh and nodal analysis through c/c++?

write a program to find the area under the curve y=f(x) between x=a & x=b


Explain the Working of strcpy Function? strcpy() : This function is meant to use to copy one string to another. The strcpy function as well accepts two strings as arguments.