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

Answer Posted / sundari.b.v

#include<iostream.h>
#include<conio.h>
class complex
{
float x;
float y;
public:
complex(){}
complex(float real,float imag)
{
x=real;
y=imag;
}
complex operator+(complex);
void display(void);
};
complex complex::operator+(complex c)
{
complex temp;
temp x=x+c.x;
temp y=x+c.y;
return
}
void complex::display(void)
{
cout<<x<<"+j"<<y<<"\n";
}
int main()
{
complex c1,c2,c3;
c1=complex(2.5,3.5);
c2=complex(1.6,2.7);
c3=c1+c2;
cout<<"c1=",c1.display();
cout<<"c2=",c2.display();
cout<<"c3=",c3.display();
return 0;
}

Is This Answer Correct ?    23 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

WHO IS INVITED WIRELESS FIDELITY TECHNOLOGY

1889


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

1716


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

2049


sir can you send me previous question paper of jsplGET entrance test

2017


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

1849






weather any body knows how th partiton of sections in rrb is aote 1,genera nowlge 2,intellgince 3,maths 4,english 5,science

2098


please send me NTPC previous papers on my email ID 18amarjeet.civil@gmail.com or mr.yadav143@gmail.com

1741


is vertical heat exchanger has better heat transfer coefficient than horizontal heat exchanger?

1012


types of highways

1061


Book for preparation of HPCL (CS/IT) .

2312


22. A solution of 1% (w/v) starch at pH 6.7 is digested by 15 μg of β‐amylase (mol wt 152,000). The rate of maltose (mol wt = 342) had a maximal initial velocity of 8.5 mg formed per min. The turnover number is

6215


plz send me bhel paper....

1858


REPO Structure and terminology

1985


Discussion Topic: “Statutory Defintions” Discussion Questions: Q1 Is it correct that a loan or an advance by a private limited company to a shareholder of the company is considered as payment of dividend? Explain your views. Q2 Will a loan or advance by a private limited company to its holding company be considered as payment of dividend if the subsidiary possesses sufficient amount of accumulated profits?

2469


What is the differents between the Physics & technical Physics

1883