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
difference between pvc and gi pipes?
What are the most asked questions for learner operators in the interview for eskom?
why does find out power factor?
WHO IS INVITED WIRELESS FIDELITY TECHNOLOGY
sir , please send me previous gate ece questionpapers with explanations.i want 15 years of gate ece question papers
plz send me bhel paper....
could u send me the model papers for drug inspector exam at imrupinder@gmail.com
Sir Pl Provide the diploma nautical science sample paper
the servents of india society was founded by ?
please send me NTPC previous papers on my email ID 18amarjeet.civil@gmail.com or mr.yadav143@gmail.com
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.
used of viscocity in petrolium
Respected sir/madam, My self R SANKAR. I am final year BE civil engineering student (2014-2018). i have shortlisted for isro exam 2018.last university exam (7th sem) result was declared i have scored 6.98CGPA. but they not provide last result mark sheet still now 1. What are the documents bring to isro exam venue? 2. either bring bonafide certificate from college instead of mark sheets?
what is the difference between interface and abstract class
richman keeps in pocket poor man throws and kids eat me am an english word P-U--E--L