有以下程序; #includeiostream 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); couta.real()+a.imag()iendl; return0; } 程序执行后的输出结果是( )。A.6+6iB.6+1iC.1+6iD.1+1i
有以下程序; #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
相关考题:
有以下程序include using namespace std;class Complex{public: Complex(double r=O, 有以下程序 #include<iostream> using namespace std; class Complex { public: Complex(double r=O,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);} private: double re,im; }; int main() { Complex a=Complex(1,1)+Complex (5); cout<<a.real()<<'+'<<a.imag()<<'i'<<endl; retum 0; } 程序执行后的输出结果是A.6+6iB.6+1iC.1+6iD.1+1i
有以下程序include using namespacestd;class Complex{public:Complex (doubler=0, d 有以下程序 #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+6iB.6+1iC.1+6iD.1+1i
有以下程序include using namespace std;class Complex{public:Complex(double r=0,d 有以下程序#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);}private: double re,im;};int main(){ Complex a =Complex(1,1)+ Complex(5); cout<<a.real()<<'+'<<a.imag()<<'i'<<end1; retura 0;}A.6+6iB.6+1iC.1+6iD.1+1i
有如下程序: include using namespace std; class Complex { double re, im, public 有如下程序: #include <iostream> using namespace std; class Complex { double re, im, public: Complex(double r, double i): re(r), im(i) {} double real() const {return re;} double image() const {return im,} Complex operator +=(Complex a) { re +=a.re; im +=a.im; return *this; } }; ostream operator << (ostream s, const Complex z) { return s<<'('<<z.real()<<','<<z.image()<<')'; } int main() { Complex x(1,-2), y(2,3); cout << (x+=y) << endl; return 0; } 执行这个程序的输出结果是( )。A.(1,-2)B.(2,3)C.(3,5)D.(3,1)
有以下程序,输出结果()。includeusing namespace std;class Complex{public:Complex(d 有以下程序,输出结果( )。 #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 imagoconst{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'<<end1; return 0; }A.6+iB.2i+5C.6+1iD.1i+5
有下列程序:includeusing namespace std;class Complex{double re,im;public:Complex 有下列程序: #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) { rA.(1,-2)B.(2,3)C.(3,5)D.(3,1)
有以下程序: include using namespace std; class Complex{public: Complex(double 有以下程序: #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+6iB.6+1iC.1+6iD.1+1i
有以下程序:includeusing namespace std;class Complex{public:Complex(dOuble r=0,d 有以下程序: #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 ComplexA.6+6iB.6+1iC.1+6iD.1+1i
(3)下列程序定义了一实部为real,虚部为imag的复数类complex,要求重载运算符“+”、“-”、“*”,实现复数对象的加法、减法、乘法运算,并编写测试程序。 class Complex { private: double real, imag; public: complex(double r, double i) { real=r; imag=i; } };