華南理工大學(xué)《高級(jí)語言程序設(shè)計(jì)(C--)》期末練習(xí)題_第1頁
華南理工大學(xué)《高級(jí)語言程序設(shè)計(jì)(C--)》期末練習(xí)題_第2頁
已閱讀5頁,還剩32頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、華南理工大學(xué) 高級(jí)語言程序設(shè) 計(jì)(C-)期末練習(xí)題一.單項(xiàng)選擇題1. 用C+語言編制的源程序要變?yōu)槟繕?biāo)程序必須要經(jīng)過()。(a) 解釋(b)匯編(c)編輯(d)編譯2.執(zhí)行 C+程序時(shí)出現(xiàn)的“溢出”錯(cuò)誤屬于() 錯(cuò)誤。(a)編譯(b) 連接(c)運(yùn)行(d)邏輯3.按 C+標(biāo)識(shí)符的語法規(guī)定,合法的標(biāo)識(shí)符是()。(a) abc(b) new(c)n咼級(jí)語言程序設(shè)計(jì)(C+)練習(xí)題(d) age4 .計(jì)算表達(dá)式 x=a=4,b=x+后,變量 x, a, b的值分別是:()(a) 4 , 4, 4(b) 4 , 4, 5(c) 4 ,5, 5(d) 5 , 4, 45 .表達(dá)式 1/2*2.0 的值是:

2、()(a) 2(b) 1(c) 0.5(d) 06 下列選項(xiàng)中,() 不能交換變量 a 和 b 的 值。(a) t=b; b=a; a=t;(b) a=a+b;b=a-b; a=a - b;(c) t=a; a=b; b=t;(d) a=b;b=a;7.有以下變量說明,下面正確的語句是 ()。int a=10, b; int &pa=a, &pb=b;(a) &pb = a; (b) pb = pa; (c) pb = &pa; (d) *pb =*pa;8 執(zhí)行下面語句序列后,a 和 b 的值分別為()。int a = 5 , b = 3 , t ;int &

3、amp;ra = a ;int &rb = b ;t = ra ; ra = rb ; rb = t ;(a) 3 和 3(b) 3 和 5(c) 5 和 3(d) 5 和 59.設(shè)X 為整型變量,不能正確表達(dá)數(shù)學(xué)關(guān)系1vXv5 的 C+邏輯表達(dá)式是()(a) 1 X 5(b)X=2|X=3|X=4(c) 1X& X5(d) !(X=5)10.設(shè) int a=1,b=2, c=3, d=4;則以下條件表達(dá)式的值為()。ab ? a : cd ? c : d(a) 1(b) 2(c) 3(d) 411.以下逗號(hào)表達(dá)式的值為()(a = 5/2, a*5 ), a*5(a) 2(b

4、) 10(d) 5012.設(shè) int x=1, y=3 , 式 3x|x-y|的 C+表達(dá)式是(a)abs(x-y)*3*x(b)3x(abs(x-y)(c) 3x|(x-y)(d)3*x*(x-y)| 3*x*(y-x)13 已知 int i=0, x=1, y=0 ;使 i 的值變成 1 的語句是(a) if( x & y ) i+ ;(b) if( x=y ) i+ ;(c) 15能正確表示代數(shù))。在下列選項(xiàng))。(c) if( x II y ) i+;(d)if( !x ) i+ ;14已知 int i=0, x=0;下面 while 語句執(zhí)行時(shí)循環(huán)次數(shù)為()Owhile( !x

5、 & i 3 ) x+ ; i+ ; (a) 4(b) 3(c) 2(d)115已知 int時(shí)循環(huán)次數(shù)為(do i-;1 );(a) 1無限16.下面()Ofor ( int i=0 cout i j en dl;i+;j-;(a) 0無限17. 執(zhí)行以下程序段后,屏幕的顯示結(jié)果是i=3;下面 do_while 語句執(zhí)行)Ocoutvvivve ndl;while(i!=(b) 2(c) 3(d)for 語句執(zhí)行時(shí)循環(huán)次數(shù)為,j=5;i=j;)(b) 5(c) 10(d)( )。i=10;s=0; dowhile(i=10); couts;(a)10(b)11(d)2118.已知 in

6、t x=1, y=0, w ;)。s=s+i; i+;(c)12執(zhí)行下面程序段后,w 的值為(if(x) if(y) w=x&y; else w=y;(a)0(b)-1確定19(c)1(d)不執(zhí)while( +x7 )cout()(a) *x=1;后輸出結(jié)果是:20.( )int(b) *(d) *執(zhí)行以下程序段后,屏幕的顯示結(jié)果是(c)i=0; do i+;while(i=0);coutvvivve ndl;(a) 0(b) 1(c) 221 以下正確的函數(shù)原型為(a) f1( int x; int y );(d) 3)。(b)void f1( x, y );(c) void f1(

7、 int x, y );(d) void f1( in t, i nt );22有函數(shù)原型 void fun2( int );卜面選項(xiàng)中,不正確的調(diào)用是()。(a) int x = 21; fu n2( x );(b)int a = 15; fu n2( a*3 );(c) int b = 100; fun2( &b );(d)fun2( 256 );23有函數(shù)原型 void fun3( int * );下面選項(xiàng)中,正確的調(diào)用是()。(a) double x = 2.17; fun3(&x );(b) int a = 15 ; fun3( a*3.14 );(c) int b

8、= 100; fun3( &b );(d)fun3( 256 );24有函數(shù)原型 void fun4( int & );下面選項(xiàng)中,正確的調(diào)用是()。(a) int x = 2.17; fun4( &x );(b)int a = 15; fun4( a*3.14 );(c) int b = 100; fun4( b );(d)fun4( 256 );25 有 聲明 int fun5( int);int(*pf)(i nt) = fun5;下面選項(xiàng)中,正確的調(diào)用是()。(a) int a=15; int n=fun5(&a);(b)int a = 15; cout

9、 (&pf)(a);(c) cout(*pf)( 256 );(d)cout n; int an;27.下列數(shù)組定義語句中,不合法的是()。(a) int a3 = 0, 1, 2, 3 ;(b)int a = 0, 1, 2 ;(c) int a3 = 0, 1, 2 ;(d)int a3 = 0 ;28已知 int a10 = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ,*p = a ;則不能表示數(shù)組 a 中元素的式子是()。(a) *a (b) *p(c) a(d) a p-a 29 .以下不能對(duì)二維數(shù)組 a 進(jìn)行正確初始化 的語句是()。(a) int a23

10、= 0 ;(b) int a3 = 0,1 , 0 ;(c)int a23= 0, 1 , 2, 3 , 4, 5 ;(d) int a3= 0, 1, 2, 3, 4, 5 ;30. 已知 int a3= 0, 1 , 2, 3,4 , 5, 6 , 7 ;則 a21的值是()。(a) 0(b) 2(c) 6(d) 731. 已知 int a33 = 1, 2, 3, 4, 5,6, 7, 8, 9 ;則不能表示數(shù)組元素a21的地址是()。(a) & a21 (b) *(a2+1)(c) a2+1(d) *(a+2)+132.已知 char*a= fortran, basic,pas

11、cal, java, C+ ;J 則 couta3;的顯示結(jié)果是()。(a) t(b) 一個(gè)地址值(c)java (d) javac+33若用數(shù)組名作為調(diào)用函數(shù)的實(shí)參,則傳遞給形參的是()。(a)數(shù)組存貯首地址(b) 數(shù)組的第一個(gè)元素值(c)數(shù)組中全部元素的值(d)數(shù)組元素的個(gè)數(shù)34. 設(shè)有變量定義 int a=3,5,7,9,11,*p=a+2, y ;執(zhí)行語句 y=*p ; 后,變量 y 的值是:()(a) 6(b) 7(c) 8(d) 935.設(shè)有變量定義 int a34;能夠表示元素 a21的值有:()(a) *a2+1(b) &a21(c)*a21(d) *(a2+1)36

12、.設(shè)有說明語句 char *s= ” ABCD ; 下 列選項(xiàng)中,輸出字符” CD”的代碼是:()(a) cout*s+2;(b)couts2;(c) couts+2;(d)coutx (c)poin t-x (d) (*po in t).y39. 已知 int a3=0,1,2,3,4 , 5,6 , 7 ; 則 a22的值是()。(a) 1(b) 3(c) 6(d) 040. 有 int ary5=1,2,3,4,5;以下表達(dá)式值等于 3 的是()o(a)aryary1(b)ary3(c)*(ary+3)(d) *ary+341.有關(guān)類和對(duì)象的說法不正確的是)(b)* int(d) int

13、 *(a)對(duì)象是類的一個(gè)實(shí)例(b)個(gè)類只能有一個(gè)對(duì)象(c)任何一個(gè)對(duì)象只能屬于一個(gè)具體的類(d) 類與對(duì)象的關(guān)系和數(shù)據(jù)類型與變 量的關(guān)系相似42.若有以下說明,在類外使用對(duì)象 objX 成員的正確語句是()。class X int a;void fun 1();public:void fun 2();X objX ;(a) objX.a=0; (b) objX.fu n1();(c) objX.fu n2(); (d) X:fu n1();43 在類定義的外部,可以被訪問的成員有()。(a)所有類成員(b) private或 protected 的類成員(c) public的類成員(d) pu

14、blic或 private 的類成員44 .說明一個(gè)類的對(duì)象時(shí),系統(tǒng)自動(dòng)調(diào)用 ();撤消對(duì)象時(shí),系統(tǒng)自動(dòng)調(diào)用()。(a)成員函數(shù)(b)構(gòu)造函數(shù)(c)析構(gòu)函數(shù)(d)友員函數(shù)45. 下面對(duì)構(gòu)造函數(shù)的不正確描述是()。(a)系統(tǒng)提供默認(rèn)的構(gòu)造函數(shù)(b) 構(gòu)造函數(shù)可以有參數(shù),所以也可以有返回值(c)構(gòu)造函數(shù)可以重載(d) 構(gòu)造函數(shù)可以設(shè)置默認(rèn)參數(shù)46. 下面對(duì)析構(gòu)函數(shù)的正確描述是()。(a)系統(tǒng)不提供默認(rèn)的析構(gòu)函數(shù)(b) 析構(gòu)函數(shù)必須由用戶定義(c) 析構(gòu)函數(shù)沒有參數(shù),也沒有返回值(d) 析構(gòu)函數(shù)可以設(shè)置默認(rèn)參數(shù)47 .關(guān)于類的靜態(tài)成員的不正確描述是 ()。(a)靜態(tài)成員不屬于對(duì)象,是類的共享成 員(

15、b)靜態(tài)數(shù)據(jù)成員要在類外定義和初始化(c)靜態(tài)成員函數(shù)不擁有 this 指針,需要 通過類參數(shù)訪問對(duì)象成員(d) 只有靜態(tài)成員函數(shù)可以操作靜態(tài)數(shù) 據(jù)成員48 .當(dāng)一個(gè)派生類公有繼承一個(gè)基類時(shí),基 類中的所有公有成員成為派生類的()。(a) public成員(b)private成員 (c)protected 成員(d)友員49.當(dāng)一個(gè)派生類私有繼承一個(gè)基類時(shí),基類中的所有公有成員和保護(hù)成員成為派生類的()。(a) public成員(b)private成員 (c)protected 成員(d)友員50.當(dāng)一個(gè)派生類保護(hù)繼承一個(gè)基類時(shí),基類中的所有公有成員和保護(hù)成員成為派生類的()。(a) publ

16、ic成員(b)private成員 (c)protected 成員(d)友員51.不論派生類以何種方式繼承基類,都不能直接使用基類的()。(a) public 成員(b)private成員(c) protected 成員(d)public成員禾口 protected 成員52在 C+中,可以被派生類繼承的函數(shù)是()。(a)成員函數(shù)(b)構(gòu)造函數(shù)(c)析構(gòu)函數(shù)(d)友員函數(shù)53.在 C+中,要實(shí)現(xiàn)動(dòng)態(tài)聯(lián)編,必須使用()調(diào)用虛函數(shù)。(a)類名(b)派生類指針(c) 對(duì)象名(d)基類指針54 下列函數(shù)中,不能說明為虛函數(shù)的是()。(a)私有成員函數(shù)(b)公有成員函數(shù)(c)構(gòu)造函數(shù) d)析構(gòu)函數(shù)55.

17、在派生類中,重載一個(gè)虛函數(shù)時(shí),要求函 數(shù)名、參數(shù)的個(gè)數(shù)、參數(shù)的類型、參數(shù)的順序和 函數(shù)的返回值()。(a)相同(b)不同(c)相容(d)部分相同56. 下面函數(shù)原型中,()聲明了 fun 為純 虛函數(shù)。(a)voidfun( )=0;(b)virtual void fun()=0;(c)virtualvoid fun();(d)virtual void fun() ;57 .若一個(gè)類中含有純虛函數(shù),則該類稱為()。(a)基類(b) 純基類(c) 抽象 類(d)派生類58 .下列流類中可以用于處理文件的是 ()。(a) ios(b) iostream (c)strstream (d) fstre

18、am59.在下列選項(xiàng)中()是 istream 類的對(duì) 象。(a) cerr(b) cin(c) clog(d) cout60.要求打開文件 D:file.dat,并能夠?qū)懭霐?shù)據(jù), 正確的語句是()o(a)ifstreamin file(“ D:file.dat V,ios:in );(b)ifstreamin file(“ D:file.dat”,ios:out );(c)ofstreamoutfile(“ D:file.dat,ios:in );(d) fstream in file(“D:file.dat”ios:i n | ios:out );二.寫出下列程序的執(zhí)行結(jié)果1. #inclu

19、deusing n amespace std; int mai n() int i=1;switch(i) case 1:i+;case 2:i+;case 3:i+; break;default:i+; couti=ie ndl;2. #in clude using n amespace std; intmai n() int i = 1;while( i=10 ) if( +i % 3 != 1 ) con ti nue;else cout i e ndl;3. #include using n amespace std;int mai n() int i=1;while (i=10) i

20、f(i%2)coutvvivv;i+;coute ndl;4. #includeusing n amespace std;int mai n() int a=0;for(i nt i=1;i=3;i+) switch(i) case 1: a=i; break; case 2: a+=i; break;case 3: a*=i;couta=ae ndl;5. #in cludeusing n amespace std;int mai n()int i,j,k;for( i=1; i=5; i+ ) for( k=1;k=5-i;cout;for(j=1;j=2*i-1;cout*;coute

21、ndl;6. #in cludeusing n amespace std;#in cludek+ )j+ )int f(int);int mai n() int i;for(i=0;i3;i+) coutvf(i)ve ndl;int f(i nt a) int b=0 , c=1; b+; c+; returnin t(a+pow(double(b),2)+c);7. #include using n amespace std;intmain;() 粘8=燧i+) cotutfWendl; int v=1; Static int z=3; y=y+10; z=z+20;return (x*y

22、+z); 8. #i nclude using n amespace std;int mai n()void f(i nt m ) cout1)f(m-1); int mai n() f(4); coute ndl; 9. #i nclude using n amespace std;int mai n() int i, coun t=0, sum=0; double average;int a= 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ;for( i=0; i10; i+ ) if( ai % 2=0 ) continue; sum+=ai;coun t+;average

23、=sum/co unt ; coutco unt=co un ttaverage= averagee ndl;10. #includeusing n amespace std; int mai n()int a= 4,3,1,-7,10,12,-2,6,9,25; int i, m ;m=a0;for(i=1;i10;i+)if(aim) m=ai; coutdata is mendl; 11. #i nclude using n amespacestd; int f(i nt b , int m,i nt n) int i,s=0;for(i=m; i n; i=i+2) s=s+bi; r

24、eturn s; int mai n() int x, a=1,2,3,4,5,6,7,8,9;x=f(a,3,6);coutvvxvve ndl;x=f(a,6,9); coutvvxvve ndl;12.#includeusing n amespace std;class A public: int f1(); intf2();void setx( int m ) x=m;coutwxwe ndl; void sety( int n ) y=n;coutwyve ndl; int getx() return x;int gety() return y; private: int x,y ;

25、int A:f1() return x+y; int A:f2() return x-y; int mai n() A a ; a.setx(10);a.sety(5);couta.getx()vv tva.gety()vve ndl ;couta.f1()vv tva.f2()vve ndl ;13. #i nclude using n amespace std;class B1 public:B1(int i) coutvv調(diào)用基類 B1 的構(gòu)造函數(shù):vvivvendl; ;class B2 public:B2(intj) coutvv調(diào)用基類 B2 的構(gòu)造函數(shù):vvjvvendl; ;c

26、lass D: public B1, public B2 public: D(i nt a,i nt b,i nt c):B2(b),B1(c),b1(a)coutvv調(diào)用派生類的構(gòu)造函數(shù):va+b*c 0y =x + 10 x c= 01.給定函數(shù)下列程序從鍵盤上輸入 x 的值,求 y 的值,在 橫線上填上適當(dāng)?shù)膬?nèi)容。#in cludeusing n amespace std; int mai n() int x , y, k ;cinx ;k = _ _(1_switch (k) case 1 : y=2*x; _ _(2) _ ;_case 0: y=x+10;coutvy=vvyve

27、ndl;2. 下面程序的功能是輸入一串字符,以“?” 號(hào)結(jié)束,統(tǒng)計(jì)其中字母?jìng)€(gè)數(shù)和數(shù)字個(gè)數(shù),在橫線 上填上適當(dāng)內(nèi)容。#i nclude using n amespace std;int mai n() int nl = 0, ng = 0 ;char ch ;cin. get(ch);while (ch != ?) if( _ _(3)_ )+ nl ;elseif ( ch= 0 & ch= 9 )+ ng;_(4!_ ;coutnnl二vvnlvv ng二n gn;3. 下面是在 100200 之間找出滿足用 3 除余 2,用 5 除余 3 和用 7 除余 2 的所有整數(shù)的程序, 在

28、橫線上填上適當(dāng)內(nèi)容。#in cludeusing n amespace std;int mai n()int i;for(i=100;i=200;(5)_)_if(_(6)_)_coutvvivve ndl;4. 下面程序的功能是求和式:1-3 5- (-1)n1(2n-1)的值,在橫線上填上適當(dāng)內(nèi)容。#in cludeusing n amespace std;int mai n() double sum=0;long n, k=1;int sig n=-1 ;cout n=;cin n;do sig n = -sig n ;sum+= _(7);k+= 2 ; while ( _ (8)_

29、);cout sum= sum endl ; 5.下面是顯示如下圖案的程序。在橫線上填上適當(dāng)?shù)膬?nèi)容。*#in cludeusing n amespace std;int mai n()int i,j ;for(i=1;i=5;i+) for(j=1;(9) _coute nds;/相當(dāng)于輸出一個(gè)空格for(j=1; (10_cout*;cout endl; 6.下面程序把 10 個(gè)數(shù)存儲(chǔ)到一維數(shù)組a中,并求該數(shù)組中最大值。在橫線上填上適當(dāng)?shù)?內(nèi)容。#in cludeusing n amespace std;int mai n() int max;int a10=76,55,95,87,85,83,65,90,77,85;int *p= a;max二*p;for( ; pmax ) max= (12) _;_coutmax= maxe ndl;7下面程序?qū)斎氲?n 求 s =

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(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)論