Sunday, January 26, 2014

C++ Program to Demonstrate Overloading Unary Operator

with 0 Comment
C++ Program to Demonstrate Overloading Unary Operator:

#include<iostream.h>
#include<conio.h>
class space
{
int x;
int z;
int y;
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<<x<<"\t";
cout<<y<<"\t";
cout<<z<<"\n";
}
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;
}

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive