有如下程序:#include<iostream> usingnamespacestd; intmain(){intf,f1=0,f2=1for(inti=3;i<=6;i++){f=f1+f2; f1=f2:f2=f}cout<<f<<endl; return0; }运行时的输出结果是()。
A.2
B.3
C.5
D.8
C、5
解析:循环3次,分别每次计算出f1,f2和f的值,该题比较简单,只需要细心即可。
A.2
B.3
C.5
D.8
C、5
解析:循环3次,分别每次计算出f1,f2和f的值,该题比较简单,只需要细心即可。
第1题
有如下程序:
#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
第2题
有如下程序: #include <iostream> using namespace std; int main() { int *p; *p = 9; cout << "The value at p: " << *p; return 0; } 编译运行程序将出现的情况是()。
A.编译时出现语法错误,不能生成可执行文件
B.运行时一定输出:The value at p:9
C.运行时一定输出:The value at p:*9
D.运行时有可能出错
第3题
有如下程序:
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;
}
执行上面程序的输出是______。
第4题
有如下程序: #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
第5题
有如下程序: #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
第6题
有如下程序: #inClude using nameSpace std; Class A{ public: A(inti=0):r1(i){ } void plint(){cout<<‘E’<<r1<<‘-’;} void print()const{cout<<‘C’<<r1*r1<<‘-’;} void print(int X){cout<<‘P’<<r1*r1*r1<<‘-’;} prlvate: intrl; }; intmain(){ Aal; constA a2(4); a1.print(2); a2.print(); returh0; } 运行时的输出结果是()。
A.P8-E4
B.P8-C16-
C.P0-E4-
D.P0-C16-
第7题
有如下程序:
#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 .输出一个不确定的数
第8题
A.构造函数的实参不允许是本类的对象
B.没有定义实现深层复制(深拷贝)的拷贝构造函数
C.构造对象a时实参与形参类型不符
D.系统不能生成缺省的拷贝构造函数
第9题
以下程序输出的结果是()。 #include<iostream> using namespace std; int main() { int **x,*y,z=10; y=&z; x=&y; cout<< **x+1<<endl; return 0; }
A.11
B.x的地址
C.y的地址
D.运行错误
第10题
A.30
B.15
C.20
D.10
第11题
下面程序的运行结果是()。 #include<iostream> using namespace std; class A { public: virtual~A() { cout<<"call A::~A()"<<endl;} }; class B:public A { char * p; public: B(int i) { p=new char[i];} ~B() { delete(p); cout<<"call B::~B()"; } }; void main() { A * a=new B(8); delete a; }
A.call B::~B()call A::~A()
B.call B::~B()
C.call A::~A()
D.call A::~A()call B::~B()