-->
当前位置:首页 > 题库

PROGRAMMING:Operation of complex number class

Luz5年前 (2021-05-10)题库457
1. Declare a complex class (real and image whose private data members are double)
2. Defines a constructor that specifies the real and imaginary parts of a complex number.
3. Define the negate member function, which can return the opposite number of the complex number when called (the real part and imaginary part are the opposite number of the original number respectively).
4. Define the member function print(), and output the current object in the format (real, image) when calling the function.
5. Write addition friend function, take complex object C1, C2 as parameters, find the sum of two complex objects.
6. Main program implementation:
(1) Read in two real numbers to initialize object C1.
(2) Read in two real numbers to initialize object C2.
(3) The results of adding C1 and C2 are calculated and output.
(4) The opposite number of C2 is calculated and the result of adding C1 is output.
###Input format:
There are two lines of input:
The first line is the real part and imaginary part of the complex number C1, separated by spaces;
The second line is the real and imaginary parts of the complex number C2, separated by spaces.
###Output format:
The output consists of three lines
The first line is the sum of C1 and C2;
The second line is the sum of the opposite number of C2 and C1;
The third line is C2.
###Input example:
Here is a set of inputs. For example:
```in
2.5 3.7
4.2 6.5
```
###Output example:
The corresponding output is given here. For example:
```out
(6.7, 10.2)
(-1.7, -2.8)
(4.2, 6.5)
```







answer:If there is no answer, please comment