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

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

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

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

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

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

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

1.在編譯指令中,宏定義使用的指令是(  )

A.#include
B.#define
C.#if
D.#else

2.基類中的protected成員,通過哪種派生,其在派生類中的可見性為protected?(  )

A.public和private
B.public和protected
C.protected和private
D.僅protected

3.基類中的public成員,通過public派生,基在派生類中的可見性為(  )

A.不可訪問
B.private
C.protected
D.public

4.不同對象調(diào)用同名函數(shù),但導(dǎo)致完全不同行為的現(xiàn)象稱為(  )

A.抽象
B.封裝
C.繼承
D.多態(tài)性

5.頭文件擴(kuò)展名為(  )

A..cpp
B..h
C..ub
D..ob

6.聲明函數(shù)為內(nèi)聯(lián)使用的關(guān)鍵字為(  )

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

7.設(shè)類A中有靜態(tài)數(shù)據(jù)成員x,兩個A類對象a和b,若

A.x=10,則
B.x的值為(  )
C.9
D.10
E.11
F.不能確定

8.C ++允許在結(jié)構(gòu)中定義函數(shù),這些函數(shù)稱為(  )

A.靜態(tài)函數(shù)
B.構(gòu)造函數(shù)
C.析構(gòu)函數(shù)
D.成員函數(shù)

9.下列哪種類型的函數(shù)適合聲明為內(nèi)聯(lián)函數(shù)?(  )

A.函數(shù)體語句較多
B.函數(shù)體邏輯較復(fù)雜
C.函數(shù)執(zhí)行時間較長
D.函數(shù)語句較少,執(zhí)行速度要求高

10.析構(gòu)函數(shù)的返回值類型為(  )

A.void
B.bool
C.int
D.無類型

11.函數(shù)重載必須滿足的條件是(  )

A.函數(shù)名相同
B.參數(shù)個數(shù)不同
C.參數(shù)類型不同
D.函數(shù)名不相同

12.下列表達(dá)式,哪個是聲明P為指向常量的常量指針?(  )

A.const int*P
B.int *const P
C.const int * const P
D.int *P

13.C++中函數(shù)中的return指令可以(  )

A.只能有一條
B.0或多條
C.至少有一條
D.只能主函數(shù)調(diào)用

14.類聲明的內(nèi)容用花括號括起來,在花括號后跟哪個符號表示類聲明結(jié)束(  )

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

15.使用new Point(5,7)創(chuàng)建對象,調(diào)用的是下列哪個構(gòu)造函數(shù)?(  )

A.Point:: Point( )
B.Point:: Point(int, int)
C.Point:: Creat( )
D.Point:: Creat(int, int)

16.類中的protected成員在何處訪問?(  )

A.只類自身成員函數(shù)中
B.只子類成員函數(shù)中
C.類和子類的成員函數(shù)中
D.通過對象類外訪問

17.在類中使用static關(guān)鍵字修飾的成員函數(shù)稱為(  )

A.全局成員函數(shù)
B.公有成員函數(shù)
C.靜態(tài)成員函數(shù)
D.非靜態(tài)成員函數(shù)

18.用于標(biāo)識十六進(jìn)制常量的前綴或后綴是(  )

A.無
B.后綴L或l
C.前綴零
D.前綴0x

19.在定義結(jié)構(gòu)時,為產(chǎn)生封裝性,則需使用哪個關(guān)鍵字?jǐn)?shù)據(jù)成員?(  )

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

20.函數(shù)模板template﹤typename T﹥void Func(T,T)不能具有哪種實(shí)例化形式?(  )

A.void Func(int, int)
B.void Func(bool, bool)
C.void Func(double, int)
D.void Func(char, char)

二、填空題(本大題共20小題,每小題1分,共20分)請在每小題的空格中填上正確答案。錯填、不填均無分。

11.在標(biāo)準(zhǔn)C++輸入/輸出方式中,用于設(shè)置轉(zhuǎn)換基數(shù)為十進(jìn)制的操控符是_______。

12.在C++的類聲明中,用public關(guān)鍵字聲明的類成員的訪問權(quán)限是_______。

13.若類的成員函數(shù)用關(guān)鍵字static進(jìn)行修飾,這樣的成員函數(shù)稱為_______。

14.虛函數(shù)類似于重載函數(shù),但與重載函數(shù)的實(shí)現(xiàn)策略不同,對虛函數(shù)的調(diào)用使用_______。

15.執(zhí)行下列代碼   cout﹤﹤showpoint﹤﹤ 123.0;   程序的輸出結(jié)果是_______。

16.C++語言中用于釋放動態(tài)分配內(nèi)存的關(guān)鍵字是_______。

17.string類中用于查找字符串中是否含有某一字符串的成員函數(shù)的第1個參數(shù)是_______。

18.C++類的構(gòu)造函數(shù)名與_______名稱一樣,且沒有返回值。

19.私有派生時,在派生類中基類的public權(quán)限變?yōu)開______。

110.C++重載“=”運(yùn)算符的函數(shù)名是_______。

111.在使用string類的find成員函數(shù)來檢索主串中是否含有指定的子串時,若在主串中不含指定的子串,find函數(shù)的返回值是_______。

112.類A有如下成員函數(shù)   int A:: fun(double x) { return (int)x/2; }   int A:: fun(int x) { return x*2; }   在主函數(shù)中有int s=fun( 6.0)+fun(2),則執(zhí)行該語句后s的值為_______。

113.重載運(yùn)算符保持其原有的操作符個數(shù),_______和結(jié)合性不變。

114.若一個程序中使用如下語句申請了一個對象數(shù)組:point *prt=new point[2];則在需要釋放pn指向的動態(tài)數(shù)組對象時,所使用的語句是_______.

115.定義虛函數(shù)所用的關(guān)鍵字是_______。

116.設(shè)要把一個文件輸出流對象myFile與文件“f:myText.txt”相關(guān)聯(lián),所用的C++語句是_______。

117.為了使用C++語言標(biāo)準(zhǔn)程序庫提供的string類,在程序中必須使用宏語句是_______。

118.C++函數(shù)中傳遞對象地址值時使用_______作為參數(shù)。

119.UML中實(shí)例連接反映對象之間的靜態(tài)關(guān)系,消息連接描述對象之間的_______ 關(guān)系。

120.使用引用作為函數(shù)參數(shù),實(shí)參對象和形參對象代表同一對象。改變形參對象的值就是改變_______對象的值。

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

21.#include ﹤iostream.h﹥   class point{   private:   float x, y;   public:   void f1(float a, float b){   x=a; y=b;   }   void get( ) {   cout ﹤﹤a﹤﹤b﹤﹤endl;   }   };   main( ) {   point a;   a. f1( 2.2, 3.3);   a. get( );   }

22.#include ﹤iostream.h﹥   class f {   private:   int x =0, y =0;   public:   void set( int a, int b) {   x=a;   y=b;   }   void get( ) {   cout﹤﹤x﹤﹤"; "﹤﹤y ﹤﹤endl;   }   };   main( ) {   f a;   a.set(1,3);   a. get( );   }

23.#include ﹤iostream.h﹥   class f {   private:   int x, y;   public:   void set( ) {   x=0; y=0;   }   void print( ) {   cout﹤﹤x﹤﹤" "﹤﹤y﹤﹤endl;   }   }   main( ) {   f a;   a. set(1,2);   a. print( );   }

24.#include ﹤iostream﹥   using namespace std;   main( ) {   int num;   max=10;   num=1;   while( num﹤max) num++;   cout ﹤﹤"num="﹤﹤num;   }

25.#include ﹤iostream.h﹥   main( ) {   int x=5, y=6;   const int *p=&x;   *p=y;   cout﹤﹤*p﹤﹤endl;   }

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

31.程序的輸出結(jié)果如下:   Parent:: Parent( ) called.   Child:: Child( ) called.   Child:: ~Called( ) called.   Parent:: ~Parent( ) called.   根據(jù)輸出結(jié)果在下面程序中的下劃線出填寫正確的語句   include ﹤iostream﹥   using namespace std;   class Parent   {   public:   Parent( ) { cout ﹤﹤"Parent:: Parent( ) called. "; }   vintual ~Parent( ) { cout ﹤﹤"Parent:: ~Parent( ) called. "; }   }:   class Child: public Parent   {   public:   Child(int i) {   cout﹤﹤"Child:: Child( ) called. ";   buf=new char[i];   }   virtual ~Child( ) {   delete [ ]buf;   cout﹤﹤"Child:: ~Child( ) called. ";   }   private:   char * buf;   };   void disp( _________ *a)   {   _________;   }   woid main( )   {   Parent *a=new Child(20);   disp(a);   int d;   cin ﹥﹥d;   }

32.在下面橫線處填上適當(dāng)?shù)恼Z句完成類的定義。   #include ﹤iostream﹥   using namespace std;   class Base {   int x;   static const int b;   public:   Base (int, int);   const int *a;   };   _________ b=15;   Base:: Base( int i, int j): _________ { }

33.輸入一個字符串,將其逆序輸出:   #include ﹤iostream﹥   using namespace std;   void main( ) {   char a[50];   memset(a, 0, sizeof(a));   int i=0, j;   char t;   cin. getline( a, 50, ' ');   for(i=0, j=_________; i﹤_________; i++, j--) {   t=a[i];   a[i]=a[j];   a[j]=t;   }   cout ﹤﹤a﹤﹤ endl;   }

34.完成下面類的定義,使其可以正確的初始化成員變量m和n:   class point {   private: int m, n;   public:   point( int, int);   point(point &t);   };   point:: point(int a, int b) {   m=a;   _________=b;   }   point:: point( _________ ) {m=t. m;   n=t. n;   }

35.在下面下劃線處填上正確的語句使序輸出結(jié)果為   201   402   3   4   5   #include ﹤iostream﹥   using namespace std;   template ﹤class T﹥   T f(T &a, T &b, int n) {   for(int i=0; i﹤n; i++) {   a[i]=a[i]+b[i];   }   return a;   }   void main( ) {   int a[5]={1,2,3,4,5};   int b[5]={100,200,300,400,500}, *p;   for(int i=0; i﹤2; i++) {   p=_________;   }   for( ; p﹤a+5; p++){   cout ﹤﹤_________﹤﹤endl;   }   }

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

41.請寫出myText 1. txt文本文件中的內(nèi)容   #include ﹤iostream﹥   #include ﹤string﹥   using namespace std;   #include ﹤fstream﹥   void main( )   {   ofstream myFile1;   myFile 1. open("myText 1. txt");   cout﹤﹤"Enter the data in Chinese format(e. g. , 2008, May 25): "﹤ endl;   string Date("2008, January 1");   string Year=Date. substr(0,4);   int k=Date. find( ",");   int i= Date. find(" ");   string Month= Date. substr(k+1, i-k-1);   tring Day = Date. substr(i+1, 2);   string NewDate=Day +" "+Month+" "+Year;   myFile1﹤﹤"original date: "﹤﹤ Date ﹤﹤ endl;   myFile1﹤﹤"Converted date: "﹤﹤NewDate ﹤﹤ endl;   myFile 1. close( );   }

42.給出下面程序的輸出結(jié)果   #include ﹤iostream﹥   using namespace std;   class Simple   {   int x, y;   public:   Simple( ) { x=y=0; }   Simple( int i, int j) { x=i; y =j; }   void copy( Simple &s);   void setxy { int i, int j) { x=i; y=j; }   void print( ) { cout ﹤﹤"x="﹤﹤x﹤﹤",y="﹤﹤y ﹤﹤ endl; }   };   void Simple:: copy( Simple &s)   {   x=s.x; y=s.y;   }   void func ( Simple s1, Simple &s2)   {   s 1. setxy(30, 40);   s 2. setxy(70, 80);   }   vpid main( )   {   Simple obj1(1, 2), obj2;   obj 2. copy(obj1);   func(obj1, obj2);   obj 1. print( );   obj 2. print( );   }

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

51.定義堆棧類模板Stack(先進(jìn)后出),棧的大小由使用者確定。要求該類模板對外提供如下二種基本操作:   (1)push入找(2)pop出棧,用數(shù)組來實(shí)現(xiàn)   #include ﹤iostream﹥   using namespace std;   template﹤class T, int size﹥   class Stack {   T x[size];   int current;   public:   Stack( ) { current =0; }   ....push(....);   ....pop(....);   }   請寫出兩個函數(shù)的過程(如果需要形式參數(shù),請給出形參類型和數(shù)量,以及返回值類型)

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

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

去領(lǐng)取

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

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

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

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

    下載