#include<iostream.h>
#include<conio.h>
class complex
{
private:
                float real,imag;
public:
                complex()
                {
                                real=imag=0.0;
                }
                void getdata()
                {
                                cout<<"Real Part ? :- ";
                                cin>>real;
                                cout<<"Imaginary Part ? :- ";
                                cin>>imag;
                }
                complex operator +(complex c2);
                void outdata(char *msg)
                {
                                cout<<endl<<msg;
                                cout<<" ( "<<real;
                                cout<<" , "<<imag<<" ) ";
                }
};
complex complex::operator +(complex c2)
{
                complex temp;
                temp.real=real+c2.real;
                temp.imag=imag+c2.imag;
                return (temp);
}
void main()
{
                clrscr();
                complex c1,c2,c3;
                cout<<"Enter Complex Number C1 _ _ _ _ _ "<<endl;
                c1.getdata();
                cout<<"Enter Complex Number C2 _ _ _ _ _ "<<endl;
                c2.getdata();
                c3=c1+c2;
                c3.outdata("C3 = C1 + C2:- ");
                getch();
}
Advertisements