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

PROGRAMMING:Member function selection calls constant member function

Luz5年前 (2021-05-10)题库427
Class to call a constant member function. Syntax points: if an object is described as a constant object, only its constant member functions can be called through the constant object, but not other member functions. Complement the definition of complete complex class (complex class, data member: constructor, output function overloaded with constant member function). Data members have real and imaginary parts, which makes the output of the program conform to the output of the topic.
class Complex
{ public:
/***Supplement the definition of complete class***/
//
private:
int Real,Imag;
};
int main()
{ Complex a(2,3); a.disp(); // Call void disp ()
const Complex b(10,20); b.disp(); // Calling void disp() const
return 0;
}
###Input format:
Read in two lines, the first line reads in two integers, representing the real part and imaginary part of the complex a, and the second line reads in two integers, representing the real part and imaginary part of the complex B.
###Output format:
Output two lines of complex numbers in different formats.
###Input example:
Here is a set of inputs. For example:
```in
1 2
10 20
```
###Output example:
The corresponding output is given here. For example:
```out
(1,2i)
[10,20j]
```







answer:If there is no answer, please comment