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

Answer Posted / manish soni

manish soni tagore collage jaipur
ph:9785261817
e_mail:monupanhar@yahoo.comf;
hapy to help;

#include<iostream>
#include<stdio.h>
#include<conio.h>
using namespace std;
struct complex
{
int real;
int img;
};

void getdata(complex &);
complex sum(complex,complex);
complex mult(complex,complex);
void display(complex);

int main()
{
complex c1,c2,c3,c4;
getdata(c1);
getdata(c2);
c3=sum(c1,c2);
cout<<"Sum= ";
display(c3);
c4=mult(c1,c2);
cout<<"MULT= ";
display(c4);
getch();
return 0;
}
complex sum(complex c1,complex c2)
{
complex c;
c.real=c1.real+c2.real;
c.img=c1.img+c2.img;
return c;
}
void display(complex c)
{
cout<<c.real<<"+"<<c.img<<"i"<<endl;


}
complex mult(complex c1,complex c2)
{
complex c;
c.real=c1.real*c2.real-c1.img*c2.img;
c.img=c1.img*c2.real+c1.real*c2.img;
return c;
}
void getdata(complex &c)
{
cout<<"Enter first complex number:"<<endl;
cout<<"Enter real ";
cin>>c.real;
cout<<"Enter img ";
cin>>c.img;
}

Is This Answer Correct ?    44 Yes 22 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

I have cleared sbi clerk and have interview in 26/04/2010.But I am M.Ed & B.Ed,i want to u know my answed about not chose the teaching post

1932


why the uncontrolled rectifiers are converting fixed ac to fixed dc only why not it is converting variable dc

1432


plz send me bhel paper....

1775


c program to compare the initial portions of the two strings and return the matched portion if matches, otherwise return the empty string.

1754


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

2115






sir , please send me previous gate ece questionpapers with explanations.i want 15 years of gate ece question papers

1773


what will the output of this program. sint a=10,b; b=a++ + ++a; printf("%d,%d,%d,%d",b,a++,a,++a)

1107


difference between pvc and gi pipes?

1425


i have M.TECH interview on RF AND MICROWAVE ENGINEERING IN IIT (KHARAGPUR/ROORKEE).KINDELY TELL WHAT SUBJECTS SHOULD I READ AND WHAT ARE THE INTERVIEW QUESTIONS.

6270


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

2047


why does find out power factor?

1451


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

1329


in which state of india has no panchayatraj

1361


types of highways

987


how to works epbx? how to configuration the epbx?

1512