更多"下列程序的运行结果是 [12] 。 include <iostrea"的相关试题:
[填空题]下列程序的运行结果是 [12] 。
include <iostream. h>
class Sample
int x,y;
public:
Sample( ) x=y=0;
Sample(int a, int b) x=a;y=b;
void disp( )
cout<<" x=" <<x<<" , y="<<y<<end1;
;
void main( )
Sample s1, s2(1, 2);
s1. disp0;
s2. disp ( );
[单项选择]下列程序的执行结果是( )。 #include<iostream.h> class Sample { int x,y; public: Sample( ) {x=y=0;} Sample(int a,int b) {x=a;y=b;} ~Sample( ) { if(x==y) cout<<"x=y"<<end1; else cout<<"x!=y"<<end1; } void disp( ) { cout<<"x="<<x<<",y="<<y<<end1; } }; void main( ) { Sample s1(2,3); s1.disp( ); }
A. x=2,y=2
B. x=3,y:3
C. x=2,y=3
D. x=3,y=2
[单项选择]以下程序的执行结果是 ______。 #include<iostream.h> class Sample { int x; public: Sample( ){}; Sample(int a){x=a;} Sample(Sample &a){x=a.x+1;} void disp( ){cout<<"x="<<x<<end1;} } void main( ) { Sample s1(2),s2(s1); s2.disp( ); }
A. x=2
B. x=3
C. x不确定
D. x=0
[单项选择]下列程序的运行结果是
#inClUde<iostream.h>
class Location
private:
int X,Y;
pubhc:
void init(int=0,int=0) ;
void valueX(int val) X=val;
int valueX( ) retum X;
void valueY(int val) Y=val;
int valueY( ) retum Y;;
void Location: :init(int initX,int initY)
X=initX;
Y=initY;
Void main( )
Location A,B;
A. init( ) ;
A. valueX(5) ;
cout < < A. valueX( ) < < endl < < A. valueY( ) < < endl;
B. init(6,2) ;
B. valueY(4) ;
cout < < B. valueX( ) < < endl < < B. valueY( ) < < endl;
A. 5
B. 0
C. 5
D. 0
[单项选择]下列程序的运行结果是 #include<iostream.h> class Location{ private: int X.Y; public: void init(int=0,int=0); void valueX(int val){X=val;} int valueX( ){ return X;} void valueY(int val){Y=val;} int valueY( ){return Y;}}; void Location::init(int init X,int init Y) { X=initX; Y=initY;} void main( ) { Location A,B; A.init( ); A.valueX(5); cout<<A.valueX( )<<endl<<A.valueY( )<<endl; B.init(6,2); B.valueY(4); cout<<B.valueX( )<<endl<<B.valueY( )<<endl;}
A. 5 0 6 4
B. 0 0 6 4
C. 5 0 6 2
D. 0 0 6 2
[单项选择]下面程序的运行结果是
#include<iostream.h>
class base{
protected:
int a;
public:
base( ) {cout < < "0";}
};
class base l: virtual base{
public:
base l ( ) {cout < <"1";}
};
class base 2: virtual base{
public:
base2 ( ) {cout < <"2";}
};
class derived: public base 1, public base2{
public:
derived( ) {cout < < "3";}
};
void main( )
{
derive obj;
cout < < endl;
}
A) 0123 B) 3120 C) 0312 D) 3012
[单项选择]下面程序的运行结果是
#include<iostream.h>
class base
protected:
int a;
public:
base( )cout <<"0";
;
class basel:virtual base
public:
basel ( ) cout <<"1";
;
class base2:virtual base
public:
base2( )cout <<"2";
;
class derived:public basel,public base2
public:
derived( )cout <<"3";
;
void main( )
derived obj;
cout <<end1;
A. 0123
B. 3120
C. 0312
D. 3012