違法信息舉報(bào) 客服熱線:400-118-7898
廣告
?
專接本欄目測試廣告

?自考C++程序設(shè)計(jì)2012年10月試題

自考 責(zé)任編輯:彭雅倩 2019-06-24

摘要:自考C++程序設(shè)計(jì)2012年10月試題及答案解析,該試卷為自考C++程序設(shè)計(jì)歷年真題試卷,包含答案及詳細(xì)解析。

自考C++程序設(shè)計(jì)2012年10月試題及答案解析

自考C++程序設(shè)計(jì)2012年10月試題及答案解析,該試卷為自考C++程序設(shè)計(jì)歷年真題試卷,包含答案及詳細(xì)解析。

一、單項(xiàng)選擇題(本大題共20小題,每小題1分,共20分。)在每小題列出的備選項(xiàng)中只有一項(xiàng)是最符合題目要求的,請將其代碼填寫在題后的括號內(nèi)。錯(cuò)選、多選或未選均不得分。

1.使用下列哪一限定符可強(qiáng)制改變訪問方式(  )

A.const
B.short
C.long
D.signed

2.下列表達(dá)式,哪一是聲明p為指向常量的指針(  )

A.const int *p;
B.int* const p;
C.const int *const p;
D.int *p;

3.運(yùn)算符:: 叫做(  )

A.下標(biāo)運(yùn)算符
B.自增運(yùn)算符
C.成員訪問運(yùn)算符
D.作用域運(yùn)算符

4.如果為一個(gè)類定義了自己的構(gòu)造函數(shù),下列描述正確的是(  )

A.系統(tǒng)不再提供默認(rèn)構(gòu)造函數(shù),但提供其他構(gòu)造函數(shù)
B.系統(tǒng)提供其他非默認(rèn)構(gòu)造函數(shù)
C.系統(tǒng)不再提供默認(rèn)構(gòu)造函數(shù)
D.系統(tǒng)仍提供默認(rèn)構(gòu)造函數(shù)

5.對于類中的成員,使用protected修飾,表明該成員的訪問權(quán)限是(  )

A.公有的
B.私有的
C.保護(hù)的
D.不可見的

6.類不是內(nèi)存中的物理實(shí)體,只有當(dāng)使用類產(chǎn)生對象時(shí),才進(jìn)行內(nèi)存分配,這種對象建立的過程稱為(  )

A.程序化
B.結(jié)構(gòu)化
C.過程化
D.實(shí)例化

7.下列關(guān)于類的權(quán)限描述錯(cuò)誤的是(  )

A.類本身的成員函數(shù)可以訪問自己定義的任何成員
B.類的對象只能訪問公有成員
C.普通函數(shù)只能通過對象訪問類的公有成員
D.一個(gè)類不能包含另一個(gè)類的對象作為成員

8.在派生中,訪問控制方式?jīng)]有下列哪種(  )

A.publish
B.public
C.protected
D.private

9.采用重載函數(shù)的目的是(  )

A.實(shí)現(xiàn)共享
B.減少空間
C.提高速度
D.使用方便,提高可讀性

10.設(shè)類A中包含若干其他類的對象作為成員,則在定義類A的構(gòu)造函數(shù)時(shí),應(yīng)使用下列哪個(gè)符號將A:: A(參數(shù)表)與成員初始化列表隔開(  )

A.,
B.;
C.:
D..

11.設(shè)存在數(shù)組a,其長度為Len,則下列哪個(gè)泛型算法用于對a進(jìn)行升冪排序(  )

A.reverse(a, a+Len);
B.sort(a, a+Len);
C.find(a, a+Len, value);
D.copy(a, a+Len, b);

12.函數(shù)int sum(int a=10, int b=15, int c=25);不可與下列哪個(gè)函數(shù)同時(shí)聲明(  )

A.int sum(int, int, int, int)
B.int sum(int, int, int)
C.int sum(double)
D.int sum(double, double, double);

13.對函數(shù)int saveName(char * first, char * sec=" ",char * thd=" ")下列調(diào)用方法不正確的是(  )

A.int s=saveName("1","2","3");
B.int s=saveName("1","2");
C.int s=saveName("1");
D.int s=saveName("1",,"3");

14.下列哪個(gè)不是函數(shù)重載需要滿足的條件(  )

A.返回值類型不同
B.參數(shù)個(gè)數(shù)不同
C.參數(shù)個(gè)數(shù)相同時(shí),參數(shù)類型不同
D.函數(shù)名相同

15.關(guān)于對象性質(zhì),下列描述錯(cuò)誤的是(  )

A.同一類對象之間不可相互賦值
B.可以使用對象數(shù)組
C.對象可以用作函數(shù)參數(shù)
D.一個(gè)對象可以用作另一個(gè)類的成員

16.可用作C++語言用戶標(biāo)識(shí)符的一組標(biāo)識(shí)符是(  )

A.void,define,+WORD
B.a3_b3,_123,YN
C.for,-abc,Case
D.2a,DO,sizeof

17.設(shè)函數(shù)int& index(int a,int i)返回?cái)?shù)組a中下標(biāo)為i的元素,如果在整型數(shù)組int array[ ]={1,2,3},在執(zhí)行index(array, 1)+=3后,array中各元素值為(  )

A.{4,2,3}
B.{1,5,3}
C.{1,2,6}
D.{4,5,6}

18.對指針動(dòng)態(tài)分配空間用的關(guān)鍵字是(  )

A.define
B.int
C.new
D.float

19.一個(gè)函數(shù)功能不太復(fù)雜,但要求被頻繁調(diào)用,應(yīng)選用(  )

A.內(nèi)聯(lián)函數(shù)
B.重載函數(shù)
C.遞歸函數(shù)
D.嵌套函數(shù)

20.在int a=3, *p=&a; 中,*p的值是(  )

A.變量a的地址值
B.無意義
C.變量p的地址值
D.3

二、填空題(本大題共20小題,每小題1分,共20分)請?jiān)诿啃☆}的空格中填上正確答案。錯(cuò)填、不填均無分。

11.默認(rèn)參數(shù)是在_________中說明的,默認(rèn)參數(shù)可以多于1個(gè),但是必須放在參數(shù)序列的后部。

12.類所聲明的內(nèi)容用_________括起來,之間的內(nèi)容稱為類體。

13.執(zhí)行代碼double pi= 3.141592;cout﹤﹤pi; 程序的輸出結(jié)果是_________。

14.在文件輸入流類中,用于判斷提取操作是否已達(dá)到文件尾的方法是_________。

15.常量成員包括常量數(shù)據(jù)成員,靜態(tài)常數(shù)成員,和_________。

16.通過C++語言中的_________機(jī)制,可以從現(xiàn)存類中構(gòu)建其子類。

17.如果一個(gè)函數(shù)直接或間接地調(diào)用自身,這樣的調(diào)用稱為_________調(diào)用。

18.使用C++編譯器對C++源程序進(jìn)行編譯產(chǎn)生文件的擴(kuò)展名是_________。

19.C++的類成員由數(shù)據(jù)成員和_________組成。

110.C++面向?qū)ο蟪绦蛟O(shè)計(jì)的特點(diǎn)為:抽象,封裝,繼承和_________。

111.C++標(biāo)準(zhǔn)庫string類中用于在主串中檢索所需字符串的成員函數(shù)是_________。

112.C++中函數(shù)參數(shù)有兩種傳遞方式:傳值和_________。

113.在刪除一個(gè)動(dòng)態(tài)對象時(shí),將自動(dòng)調(diào)用該動(dòng)態(tài)對象所屬類的_________函數(shù)。

114.在C++當(dāng)中,類外的函數(shù)只能通過類的對象使用該類的_________。

115.簡單成員函數(shù)是指聲明中不含const,volatile,_________關(guān)鍵字的函數(shù)。

116.執(zhí)行cout﹤﹤char("a"+2)﹤﹤endl; 后的顯示結(jié)果為_________。

117.假定類A有一個(gè)公有屬性的靜態(tài)數(shù)據(jù)成員b,在類外不通過對象名訪問b的寫法是_________。

118.拷貝構(gòu)造函數(shù)使用_________作為參數(shù)初始化創(chuàng)建中的對象。

119.一旦基類定義了虛函數(shù),該基類的派生類中的_________也自動(dòng)成為虛函數(shù)。

120.在C++類中,有一種類不能生成對象只能被繼承,稱之為_________。

三、改錯(cuò)題(本大題共5小題,每小題2分,共10分)

21.#include ﹤iostream.h﹥   template ﹤class T﹥   T minx(T x,T y){   if(x﹥y)   x=y;   return x;   }   void main( )   {   int a;   double d;   cout﹤﹤minx(a,d)﹤﹤endl;   }

22.#include﹤iostream.h﹥   class People{   public:   void People( ){ }   const int age( )const{return 15;}   char * name( ){return"Green";}   } ;   void main( )   {   const People s;   int i=s.age( );   cout﹤﹤"age="﹤﹤i﹤endl;   }

23.#include﹤iostream.h﹥   class A{   public: void show( ){cout﹤﹤"class A show"﹤﹤endl;}   } ;   class B{   public: void show( ){cout﹤﹤"class B show"﹤﹤endl;}   } ;   class C: public A,public B{   public: void print( ){cout﹤﹤"class C print"﹤﹤endl;}   } ;   void main( ){   C c;   c.show( );   c.print( );   }

24.#include﹤iostream.h﹥   class Student{   int x=0,y=0;   public:   Student( ){   x=1;   y=1;   }   Student(int a,int b){   x=a;   y=b;   }   void get( ){   cout﹤﹤x﹤﹤" "﹤﹤y﹤﹤endl;   }   } ;   int main( ){   Student student(5,6);   student.get( );   }

25.#include ﹤iostream.h﹥   class Base{   public:virtual void fun( )=0;   } ;   class Test:public Base{   public:virtual void fun( ){cout﹤﹤"Test.fun="﹤﹤endl;}   } ;   void main( ){   Base a;   Test *p; p=&a;   }

四、完成程序題(本大題共5小題,每小題4分,共20分)

31.在下面程序橫線處填上適當(dāng)內(nèi)容,使程序執(zhí)行結(jié)果為:40:15   程序如下:   #include ﹤iostream.h﹥   template ﹤class T﹥   T func(T x,T y){   if(sizeof(T)==8)   return _________;   else   return _________;   }   void main( ){   cout ﹤﹤func(8, 5)﹤﹤":"﹤﹤func( 5.0, 10.0)﹤﹤endl;   int d; cin ﹥﹥d;   }

32.在下面程序橫線處填上適當(dāng)內(nèi)容,使程序執(zhí)行結(jié)果為:   x=0,y=0   x=1,y=2   x=10,y=20   程序如下:   #include ﹤iostream.h﹥   class Sample   {   int x, y;   public:   Sample( ){_________}   Sample(_________){x=a;y=b;}   void disp( )   {   cout﹤﹤"x="﹤﹤x﹤﹤",y="﹤﹤y﹤﹤endl;   }   };   void main( )   {   Sample s1, s2(1, 2), s3(10, 20);   Sample *pa[3]={&s1, &s2, &s3};   for(int i=0;i﹤3;i++)   pa[i]-﹥disp( );   }

33.在下面程序橫線處填上適當(dāng)內(nèi)容,使程序執(zhí)行結(jié)果為:   n=30   程序如下:   #include ﹤iostream.h﹥   template ﹤class T﹥   class Test   {   T n;   public:   Test( ){ }   Test(T i){n=i;}   Test﹤T﹥_________(const Test﹤T﹥&s)   {   static Test﹤T﹥temp;   _________;   return temp;   }   void disp( ){cout﹤﹤"n="﹤﹤n﹤﹤endl;}   } ;   void main( )   {   Test ﹤int﹥t1(4),t2(5),t3;   t3=t1+t2;   t 3.disp( );   }

34.在下面程序橫線處填上適當(dāng)內(nèi)容,使程序執(zhí)行結(jié)果為:   n=2,sum=2   n=3,sum=5   n=5,sum=10   程序如下:   #include ﹤iostream.h﹥   class Test   {   int n;   static int sum;   public:   Test(int x){n=x;}   void add( ){_________;}   void disp( )   {   cout﹤﹤{"n="﹤﹤n﹤﹤",sum="﹤﹤sum﹤﹤endl;   }   } ;   int _________=0;   void main( )   {   Test a(2),b(3),c(5);   a.add( );   a.disp( );   b.add( );   b.disp( );   c.add( );   c.disp( );   }

35.在下面程序中的橫線處填上適當(dāng)內(nèi)容,使程序完整   #include﹤iostream.h﹥   _________   class A   {   int i;   public:   int set(B&);   int get( ){return i;}   A(int x){i=x;}   } ;   class B   {   int i;   public:   B(int x){i=x;}   _________ A;   } ;   int A:: set(B&b)   {   return i=b.i;   }   void main( )   {   A a(1);   B b(2);   cout﹤﹤a.get( )﹤﹤",";   a.set(b);   cout﹤﹤a.get( )﹤﹤endl;   }

五、程序分析題(本大題共2小題,每小題10分,共20分)

41.下面程序中A是抽象類,其輸出是什么?   #include ﹤iostream.h﹥   class A{   public:   virtual void printMe( ){cout﹤﹤"This is class A printing. "﹤﹤endl;};   } ;   class B: public A{   public:   void printMe( ) {cout ﹤﹤ "This is class B printing. "﹤﹤endl;}   } ;   class C: public B{   public:   void printMe( ) {cout ﹤﹤"This is class C printing. "﹤﹤endl;}   } ;   void print(A a)   {   a.printMe( );   }   void main( )   {   B b;   C c;   print(b); print(c);   }

42.寫出此程序的執(zhí)行結(jié)果:   #include ﹤iostream.h﹥   template﹤class T﹥   T func(T x,T y){   if(sizeof(T)==8)   return x+y;   else   return x*y;   }   void main( ){   cout ﹤﹤func(8,5)﹤﹤":"﹤﹤func( 5.0, 10.0)﹤﹤endl;   int d; cin﹥﹥d;   }

六、程序設(shè)計(jì)題(本大題共1小題,共10分)

51.設(shè)計(jì)一個(gè)Bank類,實(shí)現(xiàn)銀行某賬號的資金往來賬目管理,包括建賬號、存入、取出等。解:Bank類包括私有數(shù)據(jù)成員top(當(dāng)前賬指針),date(日期),money(金額),rest(余額)和sum(累計(jì)余額)。有三個(gè)成員函數(shù)bankin( )(處理存入賬),bankout( )(處理取出賬)和disp( )(輸出明細(xì)賬)請完成函數(shù)的實(shí)現(xiàn)。   本題程序如下:   #include ﹤stdio.h﹥   #include ﹤string.h﹥   #define Max 100   class Bank   {   int top;   char date[Max][10]; //日期   int money[Max]; //金額   int rest[Max]; //余額   static int sum; //累計(jì)余額   public:   Bank( ){top=0;}   void bankin(char d[ ],int m){…}   void bankout(char d[ ],int m){…}   void disp( ){…};   } ;

溫馨提示:因考試政策、內(nèi)容不斷變化與調(diào)整,本網(wǎng)站提供的以上信息僅供參考,如有異議,請考生以權(quán)威部門公布的內(nèi)容為準(zhǔn)!

自考備考資料免費(fèi)領(lǐng)取

去領(lǐng)取

資料下載
  • 00152《組織行為學(xué)》【知識(shí)集錦】

    下載
  • 00158《資產(chǎn)評估》【知識(shí)集錦】

    下載
  • 00148《國際企業(yè)管理》【知識(shí)集錦】

    下載
  • 00160《審計(jì)學(xué)》【知識(shí)集錦】

    下載