The class Complex
{
Public:
Complex (double r=0, double I=0) : real (r), imag (I) {}
Complex operator + (?????? ) const;//overloaded binary operator '+'
Complex operator -=(?????? );//overloaded binary operator '-='
Friend, Complex operator - (?????? ) const;//overloaded binary operator '-'
Void the Display () const;
Private:
Double real;
Double imag;
};
Void Complex: the Display () const
{
Cout & lt; <"(" & lt;
Int main ()
{
Double r, m;
Cin & gt;> R & gt;> m;
Complex c1 (r, m);
Cin & gt;> R & gt;> m;
Complex c2 (r, m);
Complex c3=c1 + c2;
C3. The Display ();
C3=c1 and c2;
C3. The Display ();
C3 -=c1;
C3. The Display ();
return 0;
}
Input format:
Input has two lines, one for two real part and imaginary part of complex
The output format:
According to the sample format output,
Input the sample:
Given a set of input here, for example:
4 2
3-5
The output sample:
Here is given the corresponding output, for example:
(7, 3)
(1, 7)
(3, 5)
CodePudding user response:
Reference:# include & lt; Iostream. H>
The class Complex
{
Public:
Complex (double r=0, double I=0) : real (r), imag (I) {}
Complex operator + (const Complex & amp;) Const;//overloaded binary operator '+'
Complex operator -=(const Complex & amp;);//overloaded binary operator '-='
Friend, Complex operator - (const Complex & amp; , const Complex & amp;);//overloaded binary operator '-'
Void the Display () const;
Private:
Double real;
Double imag;
};
Complex Complex: : operator + (const Complex & amp; C) const
{
Return the Complex (real + c.r eal, imag + c.i mag);
}
Complex Complex: : operator -=(const Complex & amp; C)
{
//real -=c.r eal;
//imag -=c.i mag;
Return the Complex (real -=c.r eal, imag -=c.i mag);
}
Void Complex: the Display () const
{
Cout & lt; <"(" & lt;}
Complex operator - (const Complex & amp; A, const Complex & amp; B)
{
Return Complex (a.r eal - b.r eal, Anderson, mag - b.i mag);
}
Int main ()
{
Double r, m;
Cin & gt;> R & gt;> m;
Complex c1 (r, m);
Cin & gt;> R & gt;> m;
Complex c2 (r, m);
Complex c3=c1 + c2;
C3. The Display ();
C3=c1 and c2;
C3. The Display ();
C3 -=c1;
C3. The Display ();
return 0;
}
//4 2
//3-5
//(7, 3)
//(1, 7)
//(3, 5)
//please press any key to continue...