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
Expected output of the program: 1. Consider the following programs. For each, indicate whether the program is correct. If yes, what is the expected output? If not, what is the

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

Depreciation to a salvage value of 0. For tax purposes an item may be depreciated over a period of several years, n. With the straight line method of depreciati

why is programming is needed now-a-days.what is the benefit of colleges to apply heavy loads on students head.

Integer literal Integer is numbers without fractional parts. e.g. 20       // Decimal 024      // Octal     0x14     // Hexadecimal To indicate long, unsigned,

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome



wap to count the numof string present in a word

How can I handle a constructor that fails?