26.consider a class complex class complex { float real; float imaginary; public: }; overload operater ‘+’ to add object of two class use parameterized constructor for accepting value of complex number.


#include<iostream.h>
#include<conio.h>
class complex
{
float real;
float imaginary;
public:
complex(float a,float b)
{
real=a;
imaginary=b;
}
void operator +(complex z)
{
float r=0;
r=real+z.real;
float i=0;
i=imaginary+z.imaginary;
cout<<“real=”<<r<<“\n imaginary=”<<i;
}
};
void main()
{
complex c(23.7,20);
complex c1(13,10.7);
clrscr();
c+c1;
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s