更多"下列程序的执行结果是( )。 #include<iostrea"的相关试题:
[简答题]下列程序的执行结果是( )。
#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( );
[单项选择]以下程序的执行结果是 ______。 #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
[填空题]下列程序的运行结果是 [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 A
public:
int a;
A( ):a(10)cout<<a<<endl;
;
void main( )
A obj1;
A obj2(obj1);
cout<<" "<<obj2.a<<endl;
A. 10 10
B. 编译错误缺少拷贝构造函数
C. 10随机数
D. 随机数随机数
[单项选择]以下程序执行结果是 ( )。 #include <iostream.h> class Base { public virtual void fun( ) { cout<<"B"; } }; class Derived { public: Derived( ) { cout<<"D"; } virtual void fun( ){ Base::fun( ); cout<<"C"; } } int main ( ) { Base *ptr; Derived obj; ptr=&obj; p->fun ( ); return 0; }
A. DBC
B. DCB
C. BDC
D. CBD
[填空题]分析以下程序的执行结果 【14】 。
#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 s 1 (2,3);
s1. disp( );
}
[单项选择]以下程序执行后的输出结果是 ( )。 #include <iostream.h> class Basel { public: void fun( ){ cout<<"Basel"<<end1; } }; class Base2 { public: void fun( ) { cout<<"Base2"<<end1; } } class Derived : public Basel,public Base2 { }; void main( ) { Derived Obj; Obj.fun( ); }
A. Basel
B. Base2
C. BaselBase2
D. 程序产生二义性
[填空题]分析以下程序的执行结果______。
#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( );
[单项选择]下列程序的输出结果是
#include
class Myclass
public:Myclass(int i=0,intj=0)
x=i;
y=j;
void show( ) cout < < "x=" < < x < < " " < "y=" < < y < < end1;
void show( )const cout < < "x=" < < " " < < "y=’ < < y < < end1;
privated:
int x; int y;
;
void main( )
Myclass my1(3,4);
const my2(7,8);
my1.show( );my2.show( );
A. x=4,y=3;x=7,y=8
B. x=3,y=4;x=7,y=8
C. x=7,y=8;x=4,y=3
D. x=8,y=7;x=7,y=8
[单项选择]下列程序的执行结果是( )。
#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”<<endl;
else
cout<<“x!=y”<<endl;
void disp( )
cout<<“x=”<<x<<“,y=”<<y<<endl;
;
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