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();
}
#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();
}