首页 > 公务员考试
题目内容 (请给出正确答案)
[主观题]

有如下程序: #include<iostream>usingnamespacestd; classTest{public: Test(){n+=2;}~Tes

有如下程序:

#include<iostream>

usingnamespacestd;

classTest

{

public:

Test(){n+=2;}

~Test(){n-=3;}

staticintgetNum(){returnn;}

private:

staticintn;

};

intTest::n=1;

intmain()

{

Test*p=neWTest;

deletep;

cout<<"n="<<Test::getNum()<<endl;

return0;

}

执行该程序的输出结果是()。

A.n=0

B.n=1

C.n=2

D.n=3

查看答案
答案
收藏
如果结果不匹配,请 联系老师 获取答案
您可能会需要:
您的账号:,可能还需要:
您的账号:
发送账号密码至手机
发送
安装优题宝APP,拍照搜题省时又省心!
更多“有如下程序: #include<iostream>using…”相关的问题
第1题
有如下程序: #include<iostream> using namespace std; int main(){ int sum;

有如下程序: #include<iostream> using namespace std; int main(){ int sum; for(int i=0;i<6;i+=3){ sum=i; for(int j=i;j<6;j++)sum+=j; } cout<<sum<<end1; return 0; } 运行时的输出结果是()。

A.3

B.10

C.12

D.15

点击查看答案
第2题
有如下程序:#include<iostream>#include<cstring>using namespace std;class XCF{in

有如下程序:

#include<iostream>

#include<cstring>

using namespace std;

class XCF{

int a;

public:

XCF(int aa=O):a(aA){cout<<”1”;}

XCF(XCF&X){a=x.a;cout<<”2”;}

~XCF(){cout<<at}

int Geta(){return at}

};

int main(){

XCF dl(5),d2(d1);

XCF半pd=new XCF(8);

cout<<pd->Geta();

delete pd;

return 0;

}

运行时的输出结果是

A.1215588

B.1218855

C.12185

D.128512

点击查看答案
第3题
有如下程序:

#include<iostream> 

usingnamespacestd; 

intmain(){

intf,f1=0,f2=1

for(inti=3;i<=6;i++){

f=f1+f2: 

f1=f2:f2=f

}

cout<<f<<endl; 

return0; 

}

运行时的输出结果是()。

A.2

B.3

C.5

D.8

点击查看答案
第4题
有如下程序: #include<iostream> usingnamespacestd; className{ charname; public: Name(){ strcpy(name,"");cout<<; } Name(char*fname){ strcpy(name,fname);cout<<; } }; intmain(){ Namenames={Name(”张三”),Name(”李四”)); return0; } 运行此程序输出符号的个数是

A.O

B.1

C.2

D.3

点击查看答案
第5题
有如下程序#include "stdio.h"main(){ int a,b,m; for(a=5;a>=1;a--) { m=0; for(b=a;b<=5;b++) m=m+a*b; } printf("%d\n",m);}上述程序的运行结果是

A.30

B.15

C.20

D.10

点击查看答案
第6题
有如下程序: #include<iostream> usingnamespacestd; voidf1(int&X,int&y){intz=X;x=y;y

有如下程序: #include<iostream> usingnamespacestd; voidf1(int&X,int&y){intz=X;x=y;y=z} voidf2(intX,inty){intz=x;x=y;y=z} intmain(){ intx=10,y=26 f1(x,y); f2(X,y); cout<<y<<endl; return0; } 运行时的输出结果是()。

A.10

B.16

C.26

D.36

点击查看答案
第7题
有如下程序: include<iostream> using namespace std; class A { public: virtual void f(){cout

有如下程序:

include<iostream>

using namespace std;

class A

{

public:

virtual void f(){cout<<"1";}

};

class B:public A

{

public:

B (){cout<<"2";}

};

class C:public B

{

public:

virtual void f(){B::f();cout<<"3";}

};

int main()

{

A aa,*p;

B bb;

C cc;

p=&cc;

p->f();

return 0;

}

执行上面程序的输出是______。

点击查看答案
第8题
有如下程序,写出该执行结果()。#include ”stdio.h”main(){ float x=2.0, y;if (x<0.0) y=0.0;else if (x<10.0) y=1.0/x;else y=1.0;printf(”%f\n”,y);}

A.0.000000

B.0.250000

C.0.500000

D.1

点击查看答案
第9题
有如下程序:#include<iostream>using namespace std;class B{public:virtual void show(){cout<

有如下程序: #include<iostream> using namespace std; class B{ public: virtual void show(){cout<<"B";} }; class D:public B{ public: void show(){cout<<"D";} }; void funl(B*ptr){ptr->show();} void fun2(B&ref);ref.show();} void fun3(B b){b.show();} int nlain(){ B b,*P=Dew D; D d; funl(p); fun2(b); fun3(d); return 0; } 程序的输出结果是

A.BBB

B.BBD

C.DBB

D.DBD

点击查看答案
第10题
有如下程序:#include <iostream.h>using namespace std;class Demo{public:Demo(){ cout<<"defau

有如下程序: #include <iostream.h> using namespace std; class Demo { public: Demo(){ cout<<"defautt constmctor\n"; } Demo(const Demo &x){cont<<"copy constmctor\n";} }; Demo userCode (Demo b){Demo c(b);return c;} int main() { Demo a,d; cout<<"calling userCode()\n"; d=userCode(a); return 0; } 执行上面程序的过程中,构造函数Demo()和Demo(const Demo&x)被调用的次数分别是()。

A.1和1

B.1和2

C.2和3

D.2和4

点击查看答案
第11题
有如下程序:#includeusing namespace std;int main(){void function(double val);double v

有如下程序:

#include

using namespace std;

int main()

{

void function(double val);

double val;

function(val);

cout<

return 0;

}

void function(double val)

{

val = 3;

}

编译运行这个程序将出现的情况是

A .编译出错,无法运行

B .输出: 3

C .输出: 3.0

D .输出一个不确定的数

点击查看答案
退出 登录/注册
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改