本栏目下题库来源于互联网,轻速云承诺对于用户导入平台的题库是严格保密的,不会在此呈现!
轻速云给您提供更好的在线考试系统服务!
2008年9月计算机等级考试二级C++笔试试题
1、【 填空题
请在下列程序中的空格处填写正确的语句:
class Sample{
public:
Sample(){}
~Sample(){}
void SetData(int data) { //将 Sample 类成员变量 data 设置成形参的值

}
private: int data;
}; [每空2分]
答案: ["64"]
2、【 填空题
有如下类定义,请将Sample类的拷贝构造函数补充完整。
class Sample{
public:
Sample(){)
~Sample() {if(p) delete p;)
Sample (const Sample& s){

}
void SetData(int data) {p=new int(data);}
private:
int*p;
}; [每空2分]
答案: ["num"]
3、【 填空题
重载加法运算符“+”,其函数名是 [每空2分]
答案: ["f0+f1"]
4、【 填空题
有如下程序:
#include<iostream>
using namespace std;
class Wages{ //“工资”类
double base; //基本工资
double bonus; //奖金
double tax; //税金
public:
Wages(double CBase, double CBonus, double CTax):
base(CBase), bonus(CBonus), tax(CTax){}
double getPay()const; //返回应付工资额
Wages operator+(Wages w)const; //重载加法
};
double Wages::getPay()const{return base+bonus-tax;}
Wages Wages::operator+(Wages w)const{
return Wages(base+w.base, bonus+w.bonus, tax+w.tax);
}
int main(){
Wages wl(2000,500,100),w2(5000,1000,300);
cout<<(wl+w2).getPay0<<end1;
retun 0;
}
程序的输出结果是 [每空2分]
答案: ["rs.eof"]
5、【 填空题
有如下程序:
#include<iostream>
using namespace std;
class Pet{
char name[10];
public:
Pet(char*name){strcpy(this->name, name);}
const char*getName()const {return name;}
virtual void call()const=0;
};
class Dog: public Pet{
public:
Dog(char*name):Pet(name){}
void call()const{cout<<"汪汪叫";}
};
class Cat:public Pet{
public:
Cat(char*name):Pet(name){}
void call()const{cout<<"喵喵叫";}
};
int main(){
Pet*pet1=new Dog("哈克"), *pet2=new Cat("吉米");
cout<<pet1->getName();pet1->call(); cout<<end1;
cout<<pet2->getName();pet2->call(); cout<<end1;
return 0;
}
程序的输出结果是 [每空2分]
答案: ["fd"]
首页 12
2页,共45个题库
2页,共45个题库
轻速云给您提供更好的在线考试系统服务!
推荐
推荐题库
众多企事业单位的信赖之选
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