2016计算机二级C++上机考前冲刺试题
基本操作题(18分)

41、请使用VC6或使用【答题】菜单打开考生文件夹projl下的工程projl,此工程中含有一个源程碍文件 projl.epp。其中位于每个注释“/pic/p>
ConstruCtor Called. The value is 10
Copy ConstruCtor Called. The value is 10
DestruCtor Called. DestruCtor Called. 注意:只修改注释“/pic/p>
/pic/p>
#inClude ’using namespaCe std; Class MyClass{
publiC:
/pic/p>
MyClass(int i)
{value=i;Cout<<”ConstruCtor Called.” < /pic/p>
{
value = P.value;
eout<<”Copy ConstruCtor Called.”< }
void Print()
{Cout<<”The value is” < /pic/p>
{Cout<<”DestruCtor Called.”< private:
int value;
}; int main()
{ MyChas objl
owl.Print();
MyClmss obj2(owl); obj2.Print();
retum 0;
简单应用题(24分)
42、请使用VC6或使用【答题】菜单打开考生文件夹pr092下的工程pros2。此工程中包含一个程序文件main.cpp,其中有“部门”类Department和“职工”类Staff的定义,还有主函数main的定义。在主函数中定义了两个“职工”对象,他们属于同一部门。程序展示,当该部门改换办公室后,这两个人的办公室也同时得到改变。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
改换办公室前:
职工号:0789姓名:张三部门:人事处办公室:521
职工号:0513姓名:李四部门:人事处办公室:521
改换办公室后:
职工号:0789姓名:张三部门:人事处办公室:311
职工号:0513姓名:李四部门:人事处办公室:311
注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/pic/p>
#include
using namespace std;
class Department{ /pic/p>
public:
Department(const char*name,const char*office){
strcpy(this一>name,nanle);
/pic/p>
}
const char*getName()const{return name;}/pic/p>
/pic/p>
const char*getOffice()const{________} /pic/p>
void changeOfficeTo(const char*office){ /pic/p>
strcpy(this一>office,office);
}
private:
char name[20];/pic/p>
char office[20];/pic/p>
};
class staff{/pic/p>
public:
/pic/p>
Staff(const char*my—id,const char木my_name,Department&my_dept):——{
strcpy(this一>staff id,my_id);
strcpy(this一>name,my_name);
}
const char*getlD()const{return staff_id;}
const char*getName()consl{return name;}
Department getDepartment()const{return dept;} char staff=id[10];/pic/p>
char name[20];/pic/p>
Department&dept;/pic/p>
}; void showStaff(Staff&staff){
cout<<”职工号:”< cout<<”姓名:”< cout<<”部门:”< cout<<”办公室:”< int main(){
Department dept(”人事处”,”521”);
Staff Zhang(”0789”,”张三”,dept),Li(”0513”,”李四”,dept);
cout<<”改换办公室前:”< showStaff(Zhang); showStaff(Li);
/pic/pic/p>
cout<<”改换办公室后:”< showStaff(Zhang); showStaff(Li);
return 0; }
综合应用题(18分)
43、
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中包含了类IntegerSet和主函数main的定义。一个IntegerSet对象就是一个整数的集合,其中包含0个或多个无重复的整数;为了便于进行集合操作,这些整数按升序存放在成员数组elem的前若干单元中。成员函数add的作用是将一个元素添加到集合中(如果集合中不存在该元素),成员函数remove从集合中删除指定的元素(如果集合中存在该元素)。请编写成员函数remove。在main函数中给出了一组测试数据,此时程序的正确输出结果应为:
2 3 4 5 27 28 31 66 75
2 3 4 5 6 27 28 31 56 75
2 3 4 5 6 19 27 28 31 66 75
3 4 5 6 19 27 28 31 66 75
3 4 5 6 19 27 28 31 66 75
要求:
补充编制的内容写在“/pic/pic/p>
注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。
/pic/p>
#ifndef INTEGERSET
#define INTEGERSET
#include
using namespace std;
const int MAXELEMENTS=100;
/pic/p>
class IntegerSet{
int elem[MAXELEMENTS];
/pic/p>
int counter; /pic/p>
puhlic:
IntegerSet():counter(0){}
/pic/p>
IntegerSet(int data[],int size);
/pic/p>
void add(int element);
/pic/p>
void remeve(int element);
/pic/p>
int getCount()const{return counter;}
/pic/p>
int getElement(int i)const{retum elem[i];}/pic/p>
void show()const;
};
void WriteToFile(char*);
#endif
/pic/p>
#include”IntegerSet.h”
#include
IntegerSet::IntegerSet(int data[],int size):counter(0){
for(int i=0;i add(data[i]);
}
}
void IntegerSet::add(int element){
int j;
/pic/p>
for(j=counter;j>0;j-)
if(element>=elem[j一1])break;
/pic/p>
if(j>0)
if(element==elem[j-1])return;
/pic/p>
/pic/p>
for(int k=counter;k>j;k一)
elem[k]=elem[k一1];
elem[j]=element;/pic/p>
counter++; /pic/p>
}
void IntegerSet::remove(int element){
/pic/p>
/pic/p>
void IntegerSet::show()const{
for(int i=0;i cout< cout< }
int main(){
int d[]={5,28,2,4,5,3,2,75,27,66,31};
IntegerSet S(d,11);S.show();
S.add(6); s.show();
S.add(19); S.show();
S.remove(2); s.show();
S.add(4); S.show();
writeToFile(””);
return 0;
}
【计算机二级C++上机考前冲刺试题】相关文章:
计算机二级《C++》上机考前冲刺试题10-01
计算机二级考试C++考前冲刺试题11-04
计算机二级《C++》上机试题及答案12-31
2016计算机二级《C++》上机冲刺题09-02
2016计算机二级C++上机试题及答案11-25
计算机二级C++上机考试试题02-14