Plural: it refers to the number a + bi that can be written in the following form. Here, a and B are real numbers, I is a virtual number unit, and I * I =-1
In the plural a + bi, a is the real part of the duplex, and B is the imaginary part of the plural.
Arithmetic Operation of the plural number:
(A + bi) + (c + di) = (a + c) + (B + d) I;
(A + bi)-(c + di) = (a-c) + (B-d) I;
(A + bi) * (c + di) = (ac-bd) + (ad + bc) I;
(A + bi)/(c + di) = (ac + bd) + (bc-ad) I)/(c * c + d * d );
Program code:
# Include
Using namespace std; template
// Declare class Complex {public: Complex () {real = 0; imag = 0;} Complex (T r, T I) {real = r; imag = I;} Complex complex_add (Complex & c2); // The Complex addition Complex complex_minus (Complex & c2); // The Complex subtraction Complex complex_multiply (Complex & c2 ); // multiplication of the Complex number Complex complex_divide (Complex & c2); // division of the Complex number void display (); // display the Complex number private: T real; // real part of the Complex number T imag; // The imaginary part of the plural number}; template
Complex
Complex
: Complex_add (Complex & c2) // Complex addition {Complex c3; c3.real = real + c2.real; c3.imag = imag + c2.imag; return c3;} template
Complex
Complex
: Complex_minus (Complex & c2) // subtraction of Complex numbers {Complex c3; c3.real = real-c2.real; c3.imag = imag-c2.imag; return c3;} template
Complex
Complex
: Complex_multiply (Complex & c2) // multiplication of Complex numbers {Complex c3; c3.real = real * c2.real-imag * c2.imag; c3.imag = real * c2.imag + imag * c2.real; return c3;} template
Complex
Complex
: Complex_divide (Complex & c2) // division of the plural {Complex c3; c3.real = (real * c2.real + imag * c2.imag)/(c2.real * c2.real + c2.imag * c2.imag ); c3.imag = (imag * c2.real-real * c2.imag)/(c2.real * c2.real + c2.imag * c2.imag); return c3;} template
Void Complex
: Display () // display the plural {if (imag> 0) // when the imaginary part is greater than 0 {cout <
Cmp1 (8,-2), Cmp2 (7, 10), Cmp3; // Add two plural numbers Cmp1.display (); cout <"+"; Cmp2.display (); cout <"="; Cmp3 = Cmp1.complex _ add (Cmp2); Cmp3.display (); cout <
Execution result:
Zookeeper