Uniary Operation Overloading
#include
#include
class complex
{
float x,y;
public:
complex()
{
x=0;
y=0;
}
complex(float real,float imag)
{
x=real;
y=imag;
}
complex operator +(complex);
void display();
};
complex complex::operator +(complex c)
{
complex t;
t.x=x+c.x;
t.y=y+c.y;
return (t);
}
void complex :: display()
{
cout<
}
void main()
{
clrscr();
complex c1,c2,c3;
c1=complex(2.5,3.5);
c2=complex(1.6,2.7);
c3=c1+c2;
cout<<" c1=";
c1.display();
cout<<" c2=";
c2.display();
cout<<" c3=";
c3.display();
getch();
}
OUTPUT
c1=2.5+i3.5
c2=1.6+i2.7
c3=4.1+i6.2
No comments:
Post a Comment