c++ program to add 2 complex number using operator
overloading technique

Answer Posted / a.bharathi raja bsc.,hdca.,

A.BHA RAJA
THENNAGALAPURI

#include<iostream.h>
#include<conio.h>
class complex
{
int r,i;
public:
{
void getdata(int a,int b)
{
r=a; i=b;
}
complex operator+(complex,complex);
void display(void);
};
complex complex :: operator+(complex a,complex b)
{
complex c;
c.r=a.r+b.r;
c.i=a.i+b.i;
return c;
}
void complex :: display(void)
{
cout<<r<<"+i"<<i<<"\n";
}
void main()
{
complex p,q,r;
int n,m;
clrscr();
cout<<"Enter the real number:";
cin>>n;
cout<<"Enter the imag number:";
cin>>m;
p.getdata(n,m);
cout<<"Enter the real number:";
cin>>n;
cout<<"Enter the imag number:";
cin>>m;
q.getdata(n,m);
r=p+q;
p.display(p);
q.display(q);
r.display(r);
getch();
}

Is This Answer Correct ?    30 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

used of viscocity in petrolium

2099


Why voltage drops in star connected motor And how IL=ph

1392


can u explain me the way to know the relation between the active as well as the reactive power acting on an electical machine under the under excitation as well as over excitation mode

2113


in vfd why we did not give directac ac supply?

2190


Book for preparation of HPCL (CS/IT) .

2312






how to resize the components?

1915


the servents of india society was founded by ?

1684


The horse has played a little known but very important role in the field of medicine. Horses were injected with toxins of diseases until their blood built up immunities. Then a serum was made from their blood.Serums to fight with diphtheria and tetanus were developed this way. It can be inferred from the passage, that horses were (A) given immunity to diseases (B) generally quite immune to diseases (C) given medicines to fight toxins (D) given diphtheria and tetanus serums

3082


types of highways

1061


What is the number which when divided by 12,15 and 24 gives remainder 5?

1145


richman keeps in pocket poor man throws and kids eat me am an english word P-U--E--L

2139


plz send me bhel paper....

1858


can i have the model papers for gate along with answers on my email id krish231191@gmail.com please???

1922


Can some1 please mail me the question papers of iiit hyderabad...my mail id is cenablogspot@gmail.com

2180


could u send me the model papers for drug inspector exam at imrupinder@gmail.com

1896