本栏目下题库来源于互联网,轻速云承诺对于用户导入平台的题库是严格保密的,不会在此呈现!
轻速云给您提供更好的在线考试系统服务!
2008年4月全国计算机等级考试二级C++笔试试题
1、【 填空题
在面向对象的程序设计中,将数据和处理数据的操作封装成一个整体就定义了一种事物的类型,称作“类”。类是一种抽象的概念,属于该类的一个实例叫做“ ”。 [每空2分]
答案: ["对象"]
2、【 填空题
指针数组是由 构成的数组。 [每空2分]
答案: ["指针或指针变量"]
3、【 填空题
如果使用数组名称为函数参数,形实结合时,传递的是 [每空2分]
答案: ["地址"]
4、【 填空题
在类的对象被创建的时候, 函数会被自动调用。 [每空2分]
答案: ["构造"]
5、【 填空题
在类中, 成员为类的所有对象所共享。 [每空2分]
答案: ["静态"]
6、【 填空题
有如下程序:
#include <iostream>
using namespace std;
class Base{
public;
int m,n;
};
class Derived1: Base{};
class Derived2: public Derived1{
public:
void SetMN(int M, int N){ M=M; n=N; }
int GetSumMN(){ retum (m+n); }
};
int main(){
Derived2 objD;
objD.SetMN(3,4);
cout<<"M+N="<<objD.m+bojD.n<<endl;
retum 0;
}
编译时只有“cout<<"M+N="<<objD.m+bojD.n<<endl;”有语法错误,程序的其他地方没有语法错误,请判断下
划线处使用的关键字是什么。 [每空2分]
答案: ["private"]
7、【 填空题
有如下程序:
#include <iostream>
using namespace std;
class Base{
int b;
public;
Base(int i) { b=i; }
void disp(){cout<<"Base: b="<<b<<;}
};
class basel; virtual public Base{
public;
Base1(int i): Base(i){}
};
class Base2:virtual public Basc{
public;
Base2(int i):Base(i){}
};
class Derived:public Base2.public Base1{
int d;
public;
Derived(int I,int j):Base1(j), Base2(j),
{ d=i; }
void disp() {cout<<"Derived: d="<<d<<"; }
};
int main(){
Derived objD(1,2); objD.disp();
objD.Basce::disp();
objD.Basce1::disp();
objD.Basce2::disp();
return 0;
}
请将程序补充完整,使程序在运行时输出:
Derived: d=1 Base: b=2 Base: b=2 Base: b=2 [每空2分]
答案: ["Base(j)"]
8、【 填空题
如下程序声明了一个电话号码类PhoneNumber,重载了流插入运算符<<,以便于电话号码的输出。请将程序补
充完整。
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class PhoneMumber{
public;
void setNumber(string number){ this->number=number; }
//重载流插入操作符
friend (ostream &output, const PhoneNumber &num)
{ output<<num.number; return output; }
private;
string number;
};
int main(){
PhoneNumber phone;
phone.setNumber("8008100598");
cout <<"The phone number is:"<<phone << end1;
return 0;
} [每空2分]
答案: ["PhoneNumber operator <<"]
9、【 填空题
如下程序声明了一个二维图形类TwoDShape,从其派生出矩形类Rec。
#include <iostream>
#include <string>
using namespace std;
class TwoDShape{ //二维图形类
char name[20];
public;
TwoDShape(char *n="unknown"){
strcpy(name, n);
}
char *getNa:ne(){ return name; }
=0;
};
class Rec : public TwoDShape{
double width, height;
public;
Rec (double w=0.0, double h=0.0):TwoDShape("rectamgle")
{ width = w; height = h; }
double getWidth(){ return width; }
double getHeight(){ return height;}
double area(){ return width*height; }
};
int main(){
TwoDShape *shape;
shape = new Rec(2.1, 3.0);
cout <<"object is"<<shape->getName()<<"\n";
cout <<"Area is"<<shape->area()<<"\n";
return 0;
}
请将程序补充完整,使程序在运行时输出:
object is triangle
Area is 6.3 [每空2分]
答案: ["virval double area()"]
10、【 填空题
如下程序声明了一个使用两个通用数据类型的模板类dataClass,其中构造函数用于初始化两个数据成员,成员
函数show 用于输出两个数据成员的数值。
#include <iostream>
using namespace std;

T1 i;
T2 j;
public;
dataClass(T1 a T2 b){ i = a; j=b; }
void show(){ cout << i <<", "<<j<<'\n'; }
};
int main(){
dataClass<int, double> ob1(10, 0.23);
dataClass<char, char *>ob2('X', "my data");
ob1.show();
ob2.show();
retum 0;
}
请将程序补充完整,使程序在运行时输出:
10, 0.23
X, my data__ [每空2分]
答案: ["templateclass dataClass"]
首页 12
2页,共50个题库
2页,共50个题库
轻速云给您提供更好的在线考试系统服务!
推荐
推荐题库
众多企事业单位的信赖之选
36万+企事业单位的共同选择
查看更多合作案例
众多企事业单位的信赖之选
开始使用轻速云组织培训考试
四步组织一场考试答题,一键搭建企业培训平台
免费使用 免费使用 预约演示
咨询热线
400-886-8169
周一到周日 8:00-22:00
©2025 轻速云 苏ICP备16049646号-1 轻速云科技提供专业的在线考试系统、在线培训系统
联系我们
客服热线客服热线:400-886-8169 | 周一至周日 8:00-22:00
©2025 轻速云 苏ICP备16049646号-1
轻速云科技提供专业的在线考试系统、在线培训系统
在线咨询 400-886-8169