有以下程序 #include <iostream> using namespace std; class Complex { public: Complex (double r=0, double i =0 :re(r) ,im (i) {} double real() const {return re;} double imag() const { return im;} Complex operator + (Complex c} const {return Complex(re+c.re, im+c.im);} privane: double re,im; }; int main { Complex a =Complex (1,1)+Complex(5); cout<<a.real()<<'+'<<a.imag() << 'i' <<endl return 0; } 程序执行后的输出结果是
A.6+6i
B.6+1i
C.1+6i
D.1+1i
第1题:
有以下程序; #include<iostream> usingnamespacestd; classComplex { public: Complex(doubler=0,doublei=O):re(r),im(i){} doublereal()const{returnre;} doubleimag()const{returnim;} Complexoperator+(Complexc)const {returnComplex(re+C.re,im+C.im);} private: doublere,im; }; intmain() { Complexa=Complex(1,1)+Complex(5); cout<<a.real()<<+<<a.imag()<<i<<endl; return0; } 程序执行后的输出结果是( )。
A.6+6i
B.6+1i
C.1+6i
D.1+1i
第2题:
有以下程序: #include <iostream> using namespace std; class Complex { public: Complex(double r=0,double i=0):re(r),im(i){ double zeal() const {return re;} double imag() const {return im;} Complex operator+(Complex c) const { return Complex(re+c.re,im+c.im);} private: double re,im; }; int main() Complex a=Complex(1,1)+Complex(5); cout<<a.real()<<'+'<<a.imag()<<'i'<<end 1; return 0; }程序执行后的输出结果是______。
A.6+6i
B.6+1i
C.1+6i
D.1+1i
第3题:
(3)下列程序定义了一实部为real,虚部为imag的复数类complex,要求重载运算符“+”、“-”、“*”,实现复数对象的加法、减法、乘法运算,并编写测试程序。 class Complex { private: double real, imag; public: complex(double r, double i) { real=r; imag=i; } };
第4题:
有下列程序: #include<iostream> using namespace std; class Complex { double re,im; public: Complex(double r,double i):re(r),im(i){} double real()const{retum re;} double image()const{return im;} Complex& operator+=(Complex A) { r
A.(1,-2)
B.(2,3)
C.(3,5)
D.(3,1)
第5题:
有以下程序: #include<iostream> using namespace std; class Complex { public: Complex(dOuble r=0,dOuble i=0):re(r),im(i){} doublereal()const{return re;} doubleimag()const{return im;} Complex operator+(Complex c)const {return Complex
A.6+6i
B.6+1i
C.1+6i
D.1+1i