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
Define Advantages of Multi File Program? The main merits of spreading a program across several files are: • Teams of programmers able to work on programs. Every programmer w

A more advanced data type is the structure; here we can define a template as a collection of different variables e.g.     struct birthdate   {     int month;     int day;

i havea a small C++ i need help with. should not be anything special for an experienced programmer

i want to check the command line argument is whether an integer or a string

hwat is the area fsdjlakl;aeklfjtealrtl;gka

write a c program to solve exanple of lamis therom

The program sorting.cpp contains a main function for testing the operation of several sort algorithms over various data sizes and data set organisations. The program understands

Explain each of the algorithms in a way that would be understandable to an intelligent person who is not familiar with programming. You should not use any code (or even pseudo code

write a program to calculate the cuboid

Asks the user for an integer. if the number is less than 21, ask them for a number again; repeat this until you get a number bigger than 20. 20 is not an acceptable number. Once yo