Friday, 31 August 2012

Operator Overloading Binary operator using C++

#include<iostream.h>
#include<conio.h>
class complex
{
float x,y;
public:
complex()
{
}
complex(float real,float imag)
{
x=real;
y=imag;
}
complex operator+(complex);
void display();
};
complex complex::operator+(complex)
{
complex temp;
temp.x=x+c.x;
tmp.y=y+c.y;
return(temp);
}
void complex::display()
{
cout<<x<<"+g"<<y<<"\n";
}
void main()
{
complex c1,c2,c3;
clrscr();
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();
}

No comments:

Post a Comment

There was an error in this gadget