一、選擇題(每小題1分,共40分)
1、關于運算符重載,下列表述中正確的是( )。
A.c++已有的任何運算符都可以重載
B.運算符函數的返回類型不能聲明為基本數據類型
C.在類型轉換符函數的定義中不需要聲明返回類型
D.可以通過運算符重載來創建c++中原來沒有的運算符
2、在類的定義中,用于為對象分配內存空間,對類的數據成員進行初始化并執行其他內部管理操作的函數是( )。
A.友元函數
B.虛函數
C.構造函數
D.析構函數
3、軟件設計中模塊劃分應遵循的準則是( )。
A.低內聚低耦合
B.高內聚低耦合
C.低內聚高耦合
D.高內聚高耦合
4、如果類A被說明成類B的友元,則( )。
A.類A的成員即類B的成員
B.類B的成員即類A的成員
C.類A的成員函數不得訪問類B的成員
D.類B不一定是類A的友元
5、有如下類定義:
class Foo
{
public:
Foo(int v):value(V){}//①
~Foo(){}//②
private:
Foo(){}//③
int value=0://④
};
其中存在語法錯誤的行是( )。
A.①
B.②
C.③
D.④
6、下面關于數組的描述錯誤的是( )。
A.在C++語言中數組的名字就是指向該數組第一個元素的指針
B.長度為n的數組,下標的范圍是0~n-1
C.數組的大小必須在編譯時確定
D.數組只能通過值參數和引用參數兩種方式傳遞給函數
7、運算符重載是對已有的運算符賦予多重含義,因此( )。
A.可以對基本類型(如int類型)的數據,重新定義“+”運算符的含義
B.可以改變一個已有運算符的優先級和操作數個數
C.只能重載c++中已經有的運算符,不能定義新運算符
D.C++中已經有的所有運算符都可以重載
8、有如下類和對象的定義:
class Constants{
public:
static double getPI(){return 3.1416;}
};
Constants constants:
下列各組語句中,能輸出3.1416的是( )。
A.cout
B.cout<
C.cout
D.cout<
9、 程序流程圖中帶有箭頭的線段表示的是( )。
A.圖元關系
B.數據流
C.控制流
D.調用關系
10、下列程序的執行結果為( )。
#include
void main()
{
int a=3,b=0;
int*P =&a;
b=+a++;
cout<<*P<<”,”<
}
A.3,4
B.4,3
C.3,4
D.4,4
[page]
11、 對長度為n的線性表排序,在最壞情況下,比較次數不是n(rt一1)/2的排序方法是( )。
A.快速排序
B.冒泡排序
C.直接插入排序
D.堆排序
12、 字面常量42、4.2、42L的數據類型分別是( )。
A.long,double、int
B.lon9、float、int
C.int、double、long
D.int、float、long
13、 下列敘述中正確的是( )。
A.棧是“先進先出”的線性表
B.隊列是“先進后出”的線性表
C.循環隊列是非線性結構
D.有序線性表既可以采用順序存儲結構,也可以采用鏈式存儲結構
14、 不能作為重載函數的調用的依據是( )。
A.參數個數
B.參數類型
C.函數類型
D.函數名稱
15、 下列語句中,錯誤的是( )。
A.const int buffer=256;
B.const double*point;
C.int const buffer=256;
D.double*eonst point:
16、 下列運算符中,在c++語言中不能重載的是( )。
A.*
B.>=
C.::
D./
17、 有如下說明:
int a[10]={1,2,3,4,5,6,7,8,9,10},* P=a; 則數值為9的表達式是( )。
A.*P+9
B.木(P+8)
C.*P+=9
D.P+8
18、 執行下列語句段后,輸出字符“*”的個數是( )。
for(int i=50;i>1;i-=2)Cout<<'*':
A.24
B.25
C.26
D.50
19、 算法的有窮性是指( )。
A.算法程序的運行時間是有限的
B.算法程序所處理的數據量是有限的
C.算法程序的長度是有限的
D.算法只能被有限的用戶使用
20、 下面關于break語句的描述中,不正確的是( )。
A.break可以用于循環體內
B.break語句可以在for循環語句中出現多次
C.break語句可以在switch語句中出現多次
D.break語句可用于if條件判斷語句內
[page]
21、 有如下類定義:
class Point
{
int xx.yy;
public:
Point():xx(0),yy(0){}
Point(int x,int Y=0):xx(X),YY(Y){}
};
若執行語句
Point a(2),b[3],幸c[4];
則Point類的構造函數被調用的次數是( )。
A.2次
B.3次
C.4次
D.5次
22、 有如下程序:
#include
using namespace std;
class Basel
{
public:
BaseI(int D.{cout<
一Basel(){}
};
class Base2
{
public:
Base2(int D.{tout<
~Base2(){}
};
class Derived:public Basel,Base2
{
public:
Derived(int a,int b,int c,int D.:Basel(B.,Base2(A.,bl(D.,b2(C.{}
private:
int bl:
int b2:
};
int main()
{
Derived d(1,2,3,4);
return 0;
}
執行這個程序的輸出結果是( )。
A.1234
B.2134
C.12
D.21
23、 以下敘述正確的是( )。
A.函數可以嵌套定義但不能嵌套調用
B.函數既可以嵌套調用也可以嵌套定義
C.函數既不可以嵌套定義也不可以嵌套調用
D.函數可以嵌套調用但不可以嵌套定義
24、 必須用一對大括號括起來的程序段是( )。
A.switCh語句中的Case標號語句
B.if語句的分支
C.循環語句的循環體
D.函數的函數體
25、 軟件按功能可以分為應用軟件、系統軟件和支撐軟件(或工具軟件)。下面屬于應用軟件的是( )。
A.學生成績管理系統
B.C語言編譯程序
C.UNIX操作系統
D.數據庫管理系統
26、 下面程序的運行結果為( )。
#include
void main()
{
for(int a=0,x=0;!x&&a<=10;a++)
{
a++:
}
cout<
}
A.10
B.1l
C.12
D.0
27、 有如下程序:
#include
using namespace std;
int i=1;
class Fun{
public:
static int i;
int value(){return i—l;}
int value()const{return i+1;}
};
int Fun::i=2;
int main(){
int i=3;
Fun funl;
const Fun fun2:
__________________
return 0;
}
若程序的輸出結果是:
123
則程序中下畫線處遺漏的語句是( )。
A.cout<
B.tout<
C.cout<
D.eout<
28、 下列有關模板的敘述中,正確的是( )。
A.函數模板不能含有常規形參
B.函數模板的一個實例就是一個函數定義
C.類模板的成員函數不能是模板函數
D.用類模板定義對象時,絕對不能省略模板實參
29、 運算符重載時不需要保持的性質是( )。
A.操作數個數
B.操作數類型
C.優先級
D.結合性
30、 下列程序的輸出結果為( )。
#include
{
if(n<1)return l;
else return n+time(n一1); return 0;
}
void main() {
cout<
}
A.0
B.10
C.15
D.16
[page]
31、 有如下程序:
#include
using namespace std;
class MyClass{
public:
MyClass(int i=0){cout<<1;}
MyClass(const MyClass&x){cout<<2;}
MyClass&operator=(const MyClass&x){cout<<3;retum$this;}
~MyClass()}cout<<4;}
};
int main()
{
MyClass objl(1),obj2(2),obj3(objl);
retum 0;
{
執行這個程序的輸出結果是( )。
A.112444
B.11114444
C.121444
D.11314444
32、 在下列模式中,能夠給出數據庫物理存儲結構與物理存取方法的是( )。
A.外模式
B.內模式
C.概念模式
D.邏輯模式
33、 有如下程序:
#inClude using namespaCe std; Class Base{
publiC:
void output(){Cout<<1;}
virtual void Print(){Cout<<'B’;} };
Class Derived:publiC Base{ publiC:
void output(){Cout<<2;} void Print(){Cout<<’D ';} };
int main() {
Base * ptr=new Derived; ptr一>output();
ptr一>Print(); delete ptr;
retum0; }
執行這個程序的輸出結果是( )。
A.1B
B.lD
C.2B
D.2D
34、以下程序中,錯誤的行為是( )。
①#include
②class A
③{
④public:
⑤ int n=2;
⑥ A(int val){cout<
⑦ -A(){};
⑧};
⑨void main() ⑩{
? A a(0);
?}
A.⑤
B.⑥
C.⑦
D.?
35、 下列數據結構中,屬于非線性結構的是( )。
A.循環隊列
B.帶鏈隊列
C.二叉樹
D.帶鏈棧
36、 有如下程序:
#inClude using namespaCe std; Class A{
publiC:
statiC int a;
void init( ){。a=1;}
A(int a=2){init( );a++;} };
int A::a:0: A obj;
int main( ) {
Cout<
}
運行時輸出的結果是( )。
A.0
B.1
C.2
D.3
37、 軟件詳細設計產生的圖如下:
該圖是( )。
A.N—S圖
B.PAD圖
C.程序流程圖
D.E—R圖
38、 秘序調試的任務是( )。
A.設計測試用例
B.驗證程序的正確性
C.發現程序中的錯誤
D.診斷和改正程序中的錯誤
39、 有如下程序:
#include
using namespace std;
class A{
public:
virtual void fancl(){cout<<”Al”;}
void func2(){cout<<”A2”;}
};
class B:public A{
public:
void funcI(){tout<<”Bl”;}
void func2(){tout<<”B2”;}
};
intmain()}
A*P=new B:
P—>funcl();
P—>func2();
delete p;
return 0;
}
執行這個程序的輸出結果是( )。
A.B182
B.A1A2
C.B1A2
D.AIB2
40、 下列字符串中。不可以用做c++標識符的是( )。
A.y_2006
B._EST_H
C.Return
D.switch
[page]
二、基本操作題(18分)
41、
請使用VC6或使用【答題】菜單打開考生文件夾projl下的工程projl,其中有枚舉DOGCOLOR、狗類Dog和主函數main的定義。程序中位于每個“//ERROR ****found****”下的語句行有錯誤,請加以改正。改正后程序的輸出結果應該是:
There is a white dog named Hoh0. There is a blaCk dog named Haha. There is a motley dog named Hihi. 注意:只修改每個//ERROR****found****女料下的那一行,不要改動程序中的其他內容。
#inClude using namespaCe std; //狗的顏色:黑、白、黃、褐、花、其他
enum DOGCOLOR{BLACK,WHITE,YELLOW,BROWN,PIEBALD,OTHER}; Class Dog{//狗類
DOGCOLOR Color; Char name[20]; statiC int Count; publiC:
Dog(Char nalTle[],DOGCOLOR Color){ strCpy(this一>name,name);
//ERROR**********found**********、
strCpy(this一>Color,Color);
} 1 DOGCOLOR getColor()Const{retum Color;}
//ERROR**********found**********
Const Char * 9etName()Const{return*finin9;} Const Char * 9etColorString()Const{
switCh(Color){
Case BLACK:return”blaCk“; Case WHITE:return”white”:
Case YELLOW:return’"yellow”: Case BROWN:return”brown”; ease PIEBALD:return”piebald”:
}
return”motley”;
}
void show()Const{ . Cout<<”There is a”<
//ERROR**********found**********
Dog dogl(”Hoh0”,WHITE),dog2(”Haha”,BLACK);d0g3(”Hihi”,0THER); d091.show();
dos2.show(); dos3.show(); return 0;
}
三、簡單應用題(24分)
42、請使用VC6或使用【答題】菜單打開考生文件夾proj2下的工程proj2。此工程中包含一個源程序文件main.cpp,其中有“房間”類Room及其派生出的“辦公室”類0ffice的定義,還有主函數main的定義。請在程序中“//****found****”下的橫線處填寫適當的代碼并刪除橫線,以實現上述類定義。此程序的正確輸出結果應為:
辦公室房間號:308
辦公室長度:5.6
辦公室寬度:4.8
辦公室面積:26.88
辦公室所屬部門:會計科
注意:只能在橫線處填寫適當的代碼,不要改動程序中的其他內容,也不要刪除或移動“///料料found??料”。
#include
using namespaee std;
class Room{ //“房間”類
int room_n0;//房間號
double length;//房間長度(m)
double width;//房間寬度(n1)
public:
Room(int the—room—n0,double the~length,double the—width):loom—no(the—room—no),length(the—
length),width(the—width){}
int theRoomNo()eonst{return iDonl—n0;}
//返回房間號
double theLength()const{return length;}//返回房間長度
double theWidth()const{return width;}//返回房間寬度
//**********found**********
double theArea()const{_______________}//返回房間面積(矩形面積)
};
class Office:public Room{//“辦公室”類
char*depart;//所屬部門
public:
Office(int the_room_n0,double the_length,double the_width,eonst char木the_depart)
//**********found**********
:_______________{
depart=new char[strlen(the depart)+1];
//**********found**********
strcpy(_______________);
}
~Office(){delete[]depart;}
const char*theDepartment()const{return depart;}//返回所屬部門
};
int main(){
//**********found**********
Office_______________;
cout<<”辦公室房間號:”<
<<”辦公室長度:”<
<<”辦公室寬度:”<
<<”辦公室面積:”<
<<”辦公室所屬部門:”<
return 0;
}
[page]
四、綜合應用題(18分)
43、請使用VC6或使用【答題】菜單打開考生目錄proj3下的工程文件proj3,此工程中包含一個源程序文件proj3.cpp,補充編制c++程序proj3.cpp,其功能是讀取文本文件in.dat中的全部內容,將文本存放到doc類的對象myDoc中。然后將myDoc中的字符序列反轉,并輸出到文件out.dat中。文件in.dat的長度不大于1000字節。
要求:
補充編制的內容寫在“//**********”與“//**********”兩行之間。實現將myDoc中的字符序列反轉,并將反轉后的序列在屏幕上輸出。不得修改程序的其他部分。
注意:程序最后已將結果輸出到文件0ut.dat中,輸出函數writeToFile已經給出并且調用。
//proj3.cpp
#include
#include
#include
using namespace std;
class doc
{
private:
char*sir;//文本字符串首地址
int length;//文本字符個數
public:
//構造函數,讀取文件內容,用于初始化新對象,filename是文件名字符串首地址
doc(char*filename);
void reverse();//將字符序列反轉
一doc();
void writeToFile(char*filename);
};
doc::doc(char}filename)
{
ifstream myFile(filename);
int len=1001,tmp;
atr=new char[1en];
length=0;
while((trap=myFile.get())!=EOF)
{
str[1ength++]=trap;
}
str[1ength]=‘\0’;
myFile.close();
}
void doc::reverse(){
//將數組atr中的length個字符中的第一個字符與最后一個字符交換,第二個字符與倒數第二個
//字符交換……
//*************333*************
//*************666*************
}
doc::~doe()
{
delete[]str;
}
void doc::writeToFile(char*filename)
{
Ofstream (filename);
<
.close();
}
void main()
{
doc myDoc(”in.dat”);
myDoc.reveme();
myDoc.writeToFile(”out.dat”);
}