2015年電大C++語(yǔ)言程序設(shè)計(jì)期末復(fù)習(xí)題資料小抄【含答案】 _第1頁(yè)
2015年電大C++語(yǔ)言程序設(shè)計(jì)期末復(fù)習(xí)題資料小抄【含答案】 _第2頁(yè)
2015年電大C++語(yǔ)言程序設(shè)計(jì)期末復(fù)習(xí)題資料小抄【含答案】 _第3頁(yè)
2015年電大C++語(yǔ)言程序設(shè)計(jì)期末復(fù)習(xí)題資料小抄【含答案】 _第4頁(yè)
2015年電大C++語(yǔ)言程序設(shè)計(jì)期末復(fù)習(xí)題資料小抄【含答案】 _第5頁(yè)
已閱讀5頁(yè),還剩5頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

電大 C+語(yǔ)言程序設(shè)計(jì)期末復(fù)習(xí)題及答案小抄資料 一、單項(xiàng)選擇題 1、 面向?qū)ο蟪绦蛟O(shè)計(jì)數(shù)據(jù)與 _放在一起,作為一個(gè)相互依存、不可分割的整體來處理。 A、對(duì)數(shù)據(jù)的操作 B、信息 C、數(shù)據(jù)隱藏 D、數(shù)據(jù)抽象 2、 已知: int a=1,b=2,c=3,d=4,則表達(dá)式 ab?a: cd?c: d 的值為 _。 A、 1 B、 2 C、 3 D、 4 3、下列 while 循環(huán)的次數(shù)是 _。 while( int i=0 ) i- -; A、 0 B、 1 C、 5 D、無限 4、以下程序的輸出結(jié)果是 _。 #include fuc( char* s) char* p=s; while( *p) p+; return (p-s); main() coutfuc(ABCDEF); A、 3 B、 6 C、 8 D、 0 5、 _的功能是對(duì)對(duì)象進(jìn)行初始化。 A、析構(gòu)函數(shù) B、數(shù)據(jù)成員 C、構(gòu)造函數(shù) D、靜態(tài)成員函數(shù) 6、下列引用的定義中, _是錯(cuò)誤的。 A、 int i; B、 int i; C、 float i; D、 char d; int& j=i; int &j; float& j=i; j=i; char &k=d; 7、若類 A 和類 B 的定義如下: class A int i,j; public: void get(); /. ; class B: public A int k; public: make(); /. ; void B:make() k=i*j; 則上述定義中, _是非法的表達(dá)式。 A、 void get(); B、 int k; C、 void make(); D、 k=i*j; 8、以下程序段 _。 int x = -1; do x = x*x; while( !x ); A、是死循環(huán) B、循環(huán)執(zhí)行 2 次 C、循環(huán)執(zhí)行 1 次 D、有語(yǔ)法錯(cuò)誤 9、對(duì)定義重載函數(shù)的下列要求中, _是錯(cuò)誤的。 A、要求參數(shù)的個(gè)數(shù)不同 B、要求參數(shù)中至少有一個(gè)類型不同 C、要求參數(shù)個(gè)數(shù)相同時(shí),參數(shù)類型不同 D、要求函數(shù)的返回值不同 10、一個(gè) _允許用戶為類定義一種模式,使得類中的某些數(shù)據(jù)成員及某些成員函數(shù)的返回值能取任意類型。 A、函數(shù)模板 B、模板函數(shù) C、類模板 D、模板類 ( Key:1-5:AAABC 6-10:BDCDC) 二、填空題 1、在 C+類中可以包含 、 和 三種具有不同訪問控制權(quán)的成員。( Key:公有或 public,保護(hù)或 protected,私有或 private) 2、以下程序的執(zhí)行結(jié)果是 _。 #include void func( int ); void func( double ); void main( ) double a=88.18; func(a); int b=97; func(b); void func( int x ) coutxendl; void func( double x ) coutx, ; (Key: 88.18, 97) 3、類中的數(shù)據(jù)和成員函數(shù)默認(rèn)訪問類型為 _。 (Key:私有或 private) 4、以下程序的執(zhí)行結(jié)果是 _。 #include using namespace std; f(int b,int n) int i,r=1; for( i=0;i=n;i+ ) r=r*bi; return r; int _tmain() int x,a = 2,3,4,5,6,7,8,9; x=f(a,3); coutx=xendl; return 0; (Key: x=120) 5、在類內(nèi)部定義的 _數(shù)據(jù)不能被不屬于該類的函數(shù)來存取,定義為 _的數(shù)據(jù)則可以在類外部進(jìn)行存取。 (Key:private 或 私有 或 protected 或 保護(hù); public 或 公有 ) 6、下列程序輸出的結(jié)果是 _。 #include using namespace std; void sub( char a,char b ) char c=a; a=b; b=c; void sub( char* a,char b ) char c=*a; *a=b; b=c; void sub( char* a,char* b ) char c=*a; *a=*b; *b=c; int _tmain() char a=A,b=B; sub(&a,&b); coutabendl; return 0; (Key: BA) 7、下列程序輸出的結(jié)果是 _。 #include using namespace std; void Exchange( int* pFirst,int* pLast ) if( pFirstpLast ) int Change = *pFirst; *pFirst = *pLast; *pLast = Change; Exchange(+pFirst,-pLast); void Print( int Integer,int HowMany) for( int Index=0; IndexHowMany; Index+ ) coutIntegerIndex ; coutendl; int _tmain() int Integer = 1,2,3,4; Exchange(&Integer0,&Integer3); Print(Integer,4); return 0; (Key: 4 3 2 1) 8、下列程序輸出的結(jié)果是 _。 #include using namespace std; int _tmain() int nInteger = 5, &rInteger = nInteger; rInteger = nInteger+1; coutnInteger,rIntegerendl; return 0; (Key: 6,6) 9、 _是一種特殊的成員函數(shù) ,它主要用來為對(duì)象分配內(nèi)存空間 ,對(duì)類的數(shù)據(jù)成員進(jìn)行初始化并進(jìn)行對(duì)象的其他內(nèi)部管理操作。 (構(gòu)造函數(shù) ) 10、下列程序輸出的結(jié)果是 _。 #include using namespace std; int _tmain() int x=2,y=3,z=4; cout( xy ) & ( !z ) | (x*y) )endl; return 0; (Key:1) 三、程序分析:給出程序運(yùn)行后的輸出結(jié)果 (每小題 5 分 ,共 20 分 ) 1、 #include using namespace std; int _tmain() int x=1,y=2,z=3; x+=y+=z; cout(xy?y:x),; cout(xy?x+:y+),; coutyendl; return 0; Key: 6,5,6 2、 #include using namespace std; void func( int b ); void main() int a = 5,6,7,8 ,i; func(a); for( i=0; i4; i+ ) coutai ; void func( int b ) int j; for( j=0; j4; j+ ) bj = 2*j; Key: 0 2 4 6 3、 #include using namespace std; class CSample int i; public: CSample(void); CSample(void); CSample(int val); void Print(void); ; CSample:CSample(void) coutConstructor1endl; i=0; CSample:CSample(int val) coutConstructor2endl; i=val; void CSample:Print(void) couti=iendl; CSample:CSample(void) coutDestructorendl; int _tmain() CSample a,b(10); a.Print(); b.Print(); return 0; Key: Constructor1 Constructor2 i=0 i=10 Destructor Destructor 4、 #include using namespace std; class CData protected: int nInteger; public: CData( int Integer ); CData( void ); void Print(void); ; CData:CData( int Integer ) : nInteger(Integer) coutConstructing a dataendl; CData:CData( void ) coutDestructing a dataendl; void CData:Print(void) coutThe data is nIntegerendl; class CNumber : public CData protected: double fNumber; public: CNumber(int Integer,double Number); CNumber(void); void Print(void); ; CNumber:CNumber( int Integer,double Number ) : CData( Integer ) , fNumber(Number) coutConstructing a numberendl; CNumber:CNumber( void ) coutDestructing a numberendl; void CNumber:Print(void) CData:Print(); coutThe number is fNumberendl; int _tmain() CNumber Number(1,3.8); Number.Print(); return 0; Key: Constructing a data Constructing a number The data is 1 The number is 3.8 Destructing a number Destructing a data 四、根據(jù)要求完成程序 1、完成以下程序,求 1!+2!+3!+4!+5!+6!+7!+8!+9!+10!之和。 #include using namespace std; int _tmain() long Term=_ ,Sum=_; for( int Index=1; Index=_; Index+) Term *=_; Sum +=_; coutSum of factorial from 1 to 10 is ; coutSumendl; return 0; Key:1 0 10 Index Term 2、完成下面程序,計(jì)算三角形和正方形的面積。設(shè)三角形和正方形的寬為 fWidth,高為 fHeight,則三角形的面積為 fWidth*fHeigth/2。 #include using namespace std; class CShape public: CSquare:CSquare(double Width,double Height) :_ double CSquare:Area(void) _; int _tmain() CTriangle Triangle(16,8); coutThe area of triangle is Triangle.Area()endl; CSquare Square(13,8); coutThe area of square is Square.Area()endl; return 0; Key: fWidth(Width) CShape(Width,Height) return fWidth*fHeight/2 CShape(Width,Height) return fWidth*fHeight 五、用面向?qū)ο蠓椒ㄔO(shè)計(jì)一個(gè)階乘類 CFactorial,在 CFactorial 類的構(gòu)造函數(shù) CFactorial(long Integer)中 ,將 Integer 的值賦給 nInteger;在主函數(shù) int _tmain(),鍵盤輸入任一整數(shù) Integer,以 Integer 的值為實(shí)際參數(shù)構(gòu)造一個(gè)階乘對(duì)象 Factorial, 調(diào)用對(duì)象 Factorial 的相應(yīng)成員函數(shù)輸出 nInteger 的階乘值fFactorial。完成以下函數(shù)的代碼設(shè)計(jì): ( 1)、設(shè)計(jì)構(gòu)造函數(shù) CFactorial(long Integer),求出 nInteger 的階乘值 fFactorial。若 nInteger 沒有階乘值,則 fFactorial 賦值為 0。 ( 2)、設(shè)計(jì) CFactorial 類的成員函數(shù) void Print(void),輸出 nInteger 的階乘值 fFactorial。若 nInteger沒有階乘,則輸出 nInteger 沒有階乘的信息。 #include using namespace std; class CFactorial public: CFactorial(long Integer); protected: long nInteger; float fFactorial; public: void Print(void); ; CFactorial:CFactorial(long Integer) : nInteger(Integer) /作答處 void CFactorial:Print(void) /作答處 int _tmain() long

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論