基本操作題(18分)
41、請使用VC6或使用【答題】菜單打開考生文件夾projl下的工程projl,此工程中含有一個源程礙文件 。其中位於每個註釋“//ERROR ****found****”之後的一行語句存在錯誤。請改正這些錯誤,使程序的輸出結果爲:
ConstruCtor Called. The value is 10
Copy ConstruCtor Called. The value is 10
DestruCtor Called. DestruCtor Called. 注意:只修改註釋“//ERROR ****found****”的下一行語句,不要改動程序中的其他內容。
//
#inClude ’using namespaCe std; Class MyClass{
publiC:
//ERROR**********found**********
MyClass(int i)
{value=i;Cout<<”ConstruCtor Called.” < //ERROR**********found********** MyClass(eonst MyClass P)
{
value = e;
eout<<”Copy ConstruCtor Called.”< }
void Print()
{Cout<<”The value is” < //ERROR**********found********* void-MyClass()
{Cout<<”DestruCtor Called.”< private:
int value;
}; int main()
{ MyChas objl
t();
MyClmss obj2(owl); t();
retum 0;
簡單應用題(24分)
42、請使用VC6或使用【答題】菜單打開考生文件夾pr092下的工程pros2。此工程中包含一個程序文件,其中有“部門”類Department和“職工”類Staff的定義,還有主函數main的定義。在主函數中定義了兩個“職工”對象,他們屬於同一部門。程序展示,當該部門改換辦公室後,這兩個人的辦公室也同時得到改變。請在程序中的橫線處填寫適當的代碼並刪除橫線,以實現上述類定義。此程序的正確輸出結果應爲:
改換辦公室前:
職工號:0789姓名:張三部門:人事處辦公室:521
職工號:0513姓名:李四部門:人事處辦公室:521
改換辦公室後:
職工號:0789姓名:張三部門:人事處辦公室:311
職工號:0513姓名:李四部門:人事處辦公室:311
注意:只在橫線處填寫適當的代碼,不要改動程序中的其他內容,也不要刪除或移動“//****found****”。
#include
using namespace std;
class Department{ //“部門”類
public:
Department(const char*name,const char*office){
strcpy(this一>name,nanle);
//**********found**********
}
const char*getName()const{return name;}//返回部門名稱
//**********found**********
const char*getOffice()const{________} //返回辦公室房號
void changeOfficeTo(const char*office){ //改換爲指定房號的另一個辦公室
strcpy(this一>office,office);
}
private:
char name[20];//部門名稱
char office[20];//部門所在辦公室房號
};
class staff{//“職工”類
public:
//**********found**********
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];//職工號
char name[20];//姓名
Department&dept;//所在部門
}; 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);
//人事處辦公室由521搬到311 //**********found********** ———————————————————————一
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