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

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

1769


If Q is the point of ABCD rectangle where QA=3CM,QB=4CM,and QC=5cm then find the length of QD ?

2459


difference between pvc and gi pipes?

1418


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

2062


how to prepare for bcil bitp

1728






types of highways

979


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

1325


what is monetary policy

1946


what is the difference between interface and abstract class

1708


why is it important to take m.e mechanical?is our l;ife make happier than other b.e courses only answer no comments

1626


Design the test cases for Boundary Value analysis of the following. Consider a program that prompts the user to input three numbers (say x, y, z) and the data type for input parameters ensures that these will be integers greater than 0 and less than or equal to 100. The program should then output the numbers in ascending order.

1531


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

1746


What is the differents between the Physics & technical Physics

1799


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

1808


REPO Structure and terminology

1905