有以下程序;#includeiostreamusingnamespacestd;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


相关考题:

有如下程序:#includeusing 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'('}int main(){Complex x(1, -2), y(2, 3);cout(x += y)return 0;}执行这个程序的输出结果是A . (1, -2)B . (2, 3)C . (3, 5)D . (3, 1)

下面是复数类 complex 的定义 , 其中重载的运算符 “ + ” 的功能是返回一个新的复 数对象 , 其实部等于两个操作对象实部之和,其虚部等于两个操作对象虚部之和;请补充完整:class complex{double real; // 实部double imag; // 虚部public:complex(double r,double i):real(r),imag(i){}complex operator+(complex a){return complex( 【 14 】 );}};

阅读以下说明和Java程序,将应填入(n)处的字句写在对应栏内[说明]以下程序的功能时三角形、矩形和正方形的面积输出。程序由5个类组成:areatest是主类,类Triangle,Rectangle和Square分别表示三角形、矩形和正方形,抽象类Figure提供了一个计算面积的抽象方法。[Java程序]public class areatest {public static viod main(string args[]){Figure[]Figures={New triangle(2,3,3),new rectangle(5,8),new square(5)};for(int i=0; i<Figures.length;i++){system.out.println(Figures+"area="+Figures.getarea());}}}public abstract class figure {public abstract double getarea();}public class rectangle extends (1) {double height;double width;public rectangle (double height,double width){this.height=height;this.width=width;}public string tostring(){return"rectangle:height="+height+",width="+width+":";}public double getarea(){return (2)}}public class square exends (3){public square(double width){(4);}public string tostring(){return"square:width="+width":";}}public class triangle entends (5){double la;double lb;double lc;public triangle(double la,double lb,double lc){this.la=la;this.lb=lb;this.lc=lc;}public string tostring()(return"triangle:sides="+la+","+lb+","+lc+":";}public double get area(){double s=(la+lb+lc)/2.0;return math.sqrt(s*(s-la)*(s-lb)*(s-lc));}}

阅读以下说明和Java源程序,将应填入(n)处的字句写在对应栏内。【说明】以下程序能够计算三角形、矩形和正方形的周长并输出。程序由5个类组成:AreaTest是主类,类Triangle、Rectangle和Square分别表示三角形、矩形和正方形,抽象类Figure提供了一个计算周长的抽象方法。【程序】public class girthTest{public static void main (String args[]){Figure[]figures={new Triangle (2,3,3),new Rectangle(5,8),new Square(5)};for(int i=0;i<figures.length;i++){System.out.println(figures[i]+"girth="+figures[i].getGirth());}}}public abstract class Figure{public abstract double getGirth();}public class Rectangle extends (1) {double height;double width;public Rectangle(double height,double width){this.height=height;this.width=width;}public String toString(){return "Rectangle:height="+height+",width="+width+":";}public double getGirth(){return (2);}}public class Square extends (3) {public Square(double width){(4);}public Stdng toString(){return "Square:width='+width+":";}}public class Triangle extends (5) {double la;double lb;double lc;public Triangle(double la,double lb,double lc){this.la=la;this.lb=lb;this.lc=lc;}public String toString(){return "Triangle:sides=" +la+"," +lb+"," +lc+":";}public double getGirth(){return la+lab+lc;}}

阅读下列Java程序和程序说明,将应填入(n)处的字句写在对应栏内。【说明】下面的程序先构造Point类,再顺序构造Ball类。由于在类Ball中不能直接存取类Point中的xCoordinate及yCoordinate属性值,Ball中的toString方法调用Point类中的toString方法输出中心点的值。在MovingBall类的toString方法中,super.toString调用父类Ball的toString方法输出类Ball中声明的属性值。public class Point{private double xCoordinate;private double yCoordinate;public Point 0 }public Point(ouble x, double y){xCoordinate = x;yCoordinate = y;}public String toString(){return "( + Double.toString(Coordinate)+ ","+ Double.toString(Coordinate) + ");}//other methods}public class Ball{(1); //中心点private double radius; //半径private String colour; ///颜色public Ball() { }public Ball(double xValue, double yValue, double r)// 具有中心点及半径的构造方法{center=(2);//调用类Point 中的构造方法radius = r;}public Ball(double xValue, double yValue, double r, String c)// 具有中心点、半径及颜色的构造方法{(3);//调用3个参数的构造方法colour = c;}public String toString(){return "A ball with center" + center, toString() + ", radius"+ Double.toString(radius) + ", colour" + colour;}//other methods}public class MovingBall. (4){private double speed;public MovingBall() { }public MovingBall(double xValue, double yValue, double r, String e, double s){(5);// 调用父类Ball中具有4个参数的构造方法speed = s;}public String toString( ){ return super, toString( ) + ", speed "+ Double.toString(speed); }//other methods}public class Tester{public static void main(String args[]){MovingBall mb = new MovingBall(10,20,40,"green",25);System.out.println(mb);}}

有以下程序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

( 13 )有如下复数类的声明,请补充完整。class complex{double real; // 实部double imag; // 虚部public:complex(double x , double y){real=x;imag=y;}perator+(complex c){// 重载加法运算符 “ + ”return complex(___________)}};

下列是定义一个接口ITF的程序,在横线处应填入的选项是 ( )public interface ITF{public static final double PI=3.14,public ______ double area(double a,double b);}A.interfaeeB.staticC.finalD.abstract

有以下程序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

有以下程序: #includeiostream usingnamespacestd; classA{ public: A( ){cout"A";} }; classB{public:B( ){cout"B";}}; classC:publicA{ Bb; public: C( ){cout"C";} }; intmain( ){Cobj;return0;} 执行后的输出结果是( )。A.CBAB.BACC.ACBD.ABC

有如下程序: 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)

阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。[说明]本程序的功能是给公司的员工Tom,Jack,Green增加薪水。三人的职位分别是programmer, Manager,CEO。程序由6个类组成:WorkerTest是主类,programmer,Manager,CEO三个类,薪水增加的规则是 programmer的涨幅是5%;Manager的是10%;CEO也是Manager,但是它除了有Manager的涨幅,还有1000元的bonus。接口SalaryRaise提供了一个增加薪水的方法raise()。[java程序]public class WorkerTest {public WorkerTest( ) {}public static void main( String[] args) {Programmer programmer = new Programmer( "Tom" ,3000);Manager manager = new Manager( "Jack" ,4000);CEO ceo = new CEO( "Green" ,4000);Worker [] worker = new Worker[3];programmer, raise( );manager, raise( );ceo. raise( );worker[0] = programmer;worker [1] = manager;worker[2] = ceo;for ( int i = 0 ;i < worker, length; i + + ) {System. out. prinfln (" Name:" + worker [i]. getName ( ) +" \ tSalary:" + worker [i]. getSalary ());public interface SalaryRaise { void raise( ); }public class Worker {public String name;public double (1);public Worker( ) {}public String getName( ) {return name;}public void setName( String name) {this. name = name;}public double getSalary( ) {return salary;}public void setSalary(double salary) { this. salary = salary; }}public class Programmer extends Worker implements (2) {public Programmer( ) {}public void raise( ) {double pets=0.05;double sala = this. getSalary( ) * (1 + pers);this. setSalary (sala);public Programmer( Siring name, double salary) tthis. name = name;this. salary = salary;public class Manager extends (3) implements SalaryRaise {public Manager( ) { }public Manager(String name, double salary) {this. name = name;this. salary = salary;}public void raise( ) {double pets = 0.1;double sala = this. getSalary() * (1 + pers);this. setSalary(sala);}}public class CEO extends Manager implements SalaryRaise {public CEO() {}public CEO( String name,double salary) {this. name = name;this. salary = salary;}public void raise( ) {double bonus = 1000;(4);double sala = this. getSalary( );(5);this. setSalary(sala);}}

有如下程序: include using namespace std; class Complex { double 有如下程序: #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); tout<<(x+=y)<<endl; return 0; } 执行这个程序的输出结果是( )。A.(1,-2)B.(2,3)C.(3,5)D.(3,1)

下列是定义一个接口ITF的程序,在横线处应填入的选项是( )。 publid interface ITF { public static final double PI=3.14; public______double area(double a,double B) ; }A.interfaceB.staticC.finalD.abstract

有以下程序,输出结果()。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

下列程序的执行结果为【 】。include class Point{public:Point(double i, double j) 下列程序的执行结果为【 】。include <iostream. h>class Point{public:Point(double i, double j) { x=i; y=j;}double Area() const { return 0.0;}private:double x, y;};class Rectangle: public Point{public:Rectangle(double i, double j, double k, double 1)double Area() const {return w * h;}private:double w, h;};Rectangle: :Rectangle(double i, double j, double k. double 1): Point(i,j).{w=k, h=1}void fun(Point s){cout<<s. Area()<<end1;}void main( ){Rectangle rec(3.0, 5.2, 15.0. 25.0);fun(rec)}

若有以下程序: #includeiostream usingnamespacestd; classBase {public: Base() {x=0;} intx;}; classDerivedl:virtualpublicBase {public: Derivedl() {x=10;}}; classDerived2:virtua11publicBase {public: Derived2() {x=20;}}; classDerived:publicDerivedl,protectedDerived2{};intmain() {Derivedobj; coutobj.xendl; return0;} 该程序运行后的输出结果是( )。A.20B.30C.10D.0

在下列程序的横线处填上适当的内容,使程序执行后的输出结果为ABCD( )。 #includeiostream usingnamespacestd; classA { public:A(){coutA;} }; classB: { public:B(){coutB;} }; classC:virtualpublicA { public:C(){coutC;} }; classD:publicB,publicD { public:D(){coutD;} }; voidmain(){D04;}A.publicAB.privateAC.protectedAD.virtualpublicA

有以下程序; #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

有以下程序:includeusing namespace std;class sample{private:int x;public:sample( 有以下程序: #include<iostream> using namespace std; class sample { private: int x; public: sample(int A) { x=a; friend double square(sample s); }; double square(sample s) { return S.X*S.K; } int main() { saA.20B.30C.900D.400

有以下程序:includeincludeusing namespace std; class point{private:double 有以下程序: #include<iostream> #include<math> using namespace std; class point { private: double x; double y; public: point(double a,double B) { x=a; y=b; } friend double distance (point a,point B) ;A.1B.5C.4D.6

有下列程序: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 sample { private: int x; public: 有以下程序 #include <iostream> using namespace std; class sample { private: int x; public: sample(int a) { x=a; } friend double square(sample s); }; double square(sample s) { return s.x*s.x; } int main() { sample s1 (20),s2(30); cout<<square(s2)<<end1; return 0; } 执行结果是A.20B.30C.900D.400

有如下程序: include using namespace std; class Complex { dou 有如下程序: #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) { remm 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(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

在接口中以下哪条定义是正确的?()A、void methoda();B、public double methoda();C、public final double methoda();D、static void methoda(double d1);E、protected void methoda(double d1);