C++語言程序設計(電大考試必備)小抄參考_第1頁
C++語言程序設計(電大考試必備)小抄參考_第2頁
C++語言程序設計(電大考試必備)小抄參考_第3頁
C++語言程序設計(電大考試必備)小抄參考_第4頁
C++語言程序設計(電大考試必備)小抄參考_第5頁
已閱讀5頁,還剩15頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、c+語言程序設計課程期末針對性訓練訓練第一套 一、單選題(每小題2分,共20分) 1在每個c+程序中都必須包含有這樣一個函數(shù),該函數(shù)的函數(shù)名為( a )。 a. main b. main c. name d. function 2設x和y均為bool量,則x & y為真的條件是( d )。 a. 其中一個為假 b. 其中一個為真 c. 它們均為假 d. 它們均為真 3. 邏輯表達式x0 | y=5的相反表達式為( b )。a. x=0 | y!=5 b. x0 | y!=5 d. x0 & y=5 4. 假定p是一個指向float型數(shù)據(jù)的指針,則p+1所指數(shù)據(jù)的地址比p所指數(shù)據(jù)的地址大( c

2、)個字節(jié)。 a. 1 b. 2 c. 4 d. 8 5. 枚舉類型中的每個枚舉常量的值都是一個( a )。 a. 整數(shù) b. 浮點數(shù) c. 字符 d. 邏輯值 6. 循環(huán)體至少被執(zhí)行一次的語句為( c )語句。 a. for循環(huán) b. while循環(huán) c. do循環(huán) d. 任一種循環(huán) 7. 在下面的字符數(shù)組定義中,( d )語句有語法錯誤。 a. char a20=”abcdefg”; b. char a=”x+y=55.”; c. char a15=1,2; d. char a10=5; 8. 若用數(shù)組名作為函數(shù)調用的實參,傳遞給形參的是( a )。 a. 數(shù)組的首地址 b. 數(shù)組中第一個元

3、素的值 c. 數(shù)組全部元素的值 d. 數(shù)組元素的個數(shù) 9假定ab為一個類,則執(zhí)行“ab a(4), b5, *p2;”語句時,自動調用該類構造函數(shù)的次數(shù)為( a )。 a. 6 b. 7 c. 9 d. 11 10當使用fstream流類定義一個流對象并打開一個磁盤文件時,文件的隱含打開方式為( d )。 a. ios:in b. ios:out c. ios:in | ios:out d. 沒有 二、填空題(每小題2分,共20分) 1. 若需要定義一個標識符常量,并且使c+能夠進行類型檢查,則應在定義語句的開始使用保留字_ const _。 2. 算術表達式對應的c+表達式為_(x*y*y)

4、/(3*a)+4*b-1 _。 3. 邏輯表達式xy & x!=10的相反表達式為_ x=y | x=10_。 4. 每個字符指針變量占用內存_4_個字節(jié)。 5. 執(zhí)行“typedef int datatype;”語句后,在使用int定義整型變量的地方都可以使用標識符_ datatype _來定義整型變量。 6. 對于在所有函數(shù)定義之外定義的變量,若沒有被初始化則系統(tǒng)隱含對它賦予的初值為_0_。 7假定p所指對象的值為25,p+1所指對象的值為46,則執(zhí)行“*(p+);”語句后,p所指對象的值為_46_。 8假定一個結構類型的定義為“struct aint a; double* b; a* c

5、;”,則該類型的大小為_12_字節(jié)。 9假定一維數(shù)組的定義為“int a8;”,則該數(shù)組所含元素的個數(shù)為_8_。 10. 若while循環(huán)語句的開始為”while(i+=10)”,若i的初值為0,同時在循環(huán)體中不會修改i的值,則其循環(huán)體將被重復執(zhí)行_11_次后正常結束。 三、寫出下列每個程序運行后的輸出結果(每小題6分,共30分) 1. #include void main() int s1=0, s2=1; for(int i=1; i=6; i+) s1+=i; s2*=i; couts1,s2endl; 輸出結果:21,720 2. #include void main() int a1

6、0=68,79,86,65,46,94,37,78,60,53; int c=0; for(int i=0;i=60) c+; cout”c=”cendl; 輸出結果:c=7 3. #include void main() int a34=1,2,7,8,5,6,11,15,9,20,3,4; int m=a00; for(int i=0;i3;i+) for(int j=0;jm) m=aij; coutmendl; 輸出結果:20 4. #include void main() int a=10, b=15; couta b ; a*=3; int b=a+20; couta b ; co

7、uta bendl; 輸出結果:10 15 30 50 30 15 5. #include void main() int a8=6,19,4,12,20,5,18,25; int* p=a; for(p=a; pa+8;p+) if(*p10) cout*p ; coutendl; 輸出結果:6 4 5 四、寫出下列每個函數(shù)的功能(每小題8分,共24分) 1. bool wb(int a, int n, int x) for(int i=0;in;i+) if(ai=x) return true; return false; 函數(shù)功能:從數(shù)組a中順序查找值為x的元素,若查找成功則返回真,否則

8、返回假。 2. int lj(int a, int n) int k=0; for(int i=1;iak) k=i; return ak; 函數(shù)功能:求出數(shù)組a中n個元素的最大值并返回。 3. 假定結構類型dnode中的data域為結點值域,next域為結點指針域。 dnode* qb(int n) if(n=0) return null; dnode* f=new dnode; cinf-data; dnode* p=f; while(-n) p=p-next=new dnode; cinp-data; p-next=null; return f; 函數(shù)功能:建立一個具有n個結點的鏈表,每

9、個結點的值依次由鍵盤輸入,該函數(shù)返回其表頭指針。 五、按題目要求編寫程序(6分) 已知6a30、15b36,求出滿足不定方程2a+5b=126的全部整數(shù)組解。如(13,20)就是其中的一組解,并按此格式輸出每組解。答: #include void main() int a,b; for(a=6;a=30; a+) for(b=15;b=36;b+) if(2*a+5*b=126) cout(a,b)endl; 訓練第二套 一、單選題(每小題2分,共20分) 1. 枚舉類型中的每個枚舉常量的值都是一個( a )值。 a. 整數(shù) b. 浮點數(shù) c. 字符 d. 邏輯 2設x和y均為bool量,則邏

10、輯表達式x | y為假的條件是( c )。 a. 它們均為真 b. 其中一個為真 c. 它們均為假 d. 其中一個為假 3. 聲明或定義一個內聯(lián)函數(shù)時,必須在函數(shù)開始使用保留字( d )。 a. static b. const c. extern d. inline 4. 在下面的函數(shù)聲明中,存在著語法錯誤的是( d )。 a. bc(int a, int); b. bc(int, int); c. bc(int, int=5); d. bc(int x; int y); 5. 假定a為一個整型數(shù)組名,則元素a4與( c )的表示等價。 a. a+4 b. *a+4 c. *(a+4) d.

11、*(a+16) 6. 下面循環(huán)語句執(zhí)行結束后輸出的i值為( b )的值。 for(int i=0; in/2) coutiendl; break; a. n/2 b. n/2+1 c. n-1 d. n 7. 將兩個字符串連接起來組成一個字符串時,選用( c )函數(shù)。 a. strlen() b. strcpy() c. strcat() d. strcmp() 8. 預處理命令在程序中都是以( b )字符開頭的。 a. * b. # c. & d. 9. 假定有定義“struct bookchar title40; float price;”,則不正確的變量定義語句為( d )。 a. bo

12、ok x; ; b. book x=c+ programming,27.0; c. book *x=new book; d. book x=new book; 10. 假定ab為一個類,px為指向該類動態(tài)對象數(shù)組的指針,該數(shù)組長度為n,則執(zhí)行“delete px;”語句時,自動調用該類析構函數(shù)的次數(shù)為( b )。 a. 1 b. n c. n-1 d. n+1 二、填空題(每小題2分,共20分) 1已知az的ascii碼為6590,當執(zhí)行“char ch=14*4+12;coutch;”語句序列后,得到的輸出結果為_d_。 2double類型的長度為_8_。 3. 表達式x=x+1表示成增量表

13、達式為_+x _。4. 邏輯表達式ab & b!=15_。 5. 假定一個二維數(shù)組的定義為“char* a54;”,則該數(shù)組所含元素的個數(shù)為_20_,所占存儲空間的字節(jié)數(shù)為_80_。 6當函數(shù)中的_局部_變量沒有被賦初值時,它的值是不確定的。 7假定一個結構類型的定義為“struct adouble a,b; a* c;”,則該類型的大小為_20_字節(jié)。 8. 假定要訪問一個結構指針p所指對象中的數(shù)據(jù)成員data,則表示方法為_ p-data _。 9假定用戶沒有給一個名為ab的類定義構造函數(shù),則系統(tǒng)為其隱含定義的構造函數(shù)為 ab()_。 10. 當在程序中執(zhí)行到 break 語句時,就立即結

14、束本層循環(huán)類語句或switch語句的執(zhí)行。 三、寫出下列每個程序運行后的輸出結果(每小題6分,共30分) 1. #include void main() int s=0; for(int i=1;i=8;i=+2) s+=i*i; couts=sendl; 輸出結果:s=84 2. #include void main() int i=1,s=0; while(s20) if(i%2!=0) s+=i; i+; couti,sendl; 輸出結果:10,25 3. #include void main() int a8=36,25,48,14,55,20,47,82; int b1, b2;

15、b1=b2=a0; for(int i=1; i8; i+) if(aib2) b2=ai; coutb1,b2endl; 輸出結果:14,82 4. #include int lb(int *a, int n) int s=1; for(int i=0;in;i+) s*=*a; a+; return s; void main() int a5=1,2,3,4,5; coutlb(a,5)endl; 輸出結果:120 5. #include struct worker char name15; /姓名 int age; /年齡 float pay; /工資 ; void main() wor

16、ker x=wangfong,46,1640; worker y, *p; y=x; p=&x; y.age y.payendl; coutname age+5 pay-300endl; 輸出結果:wangfong 46 1640 wangfong 51 1340 四、寫出下列每個函數(shù)的功能(每小題8分,共24分) 1. int wc(int a, int n, int k) int c=0; for(int i=0;i=k) c+; return c; 函數(shù)功能:統(tǒng)計出數(shù)組a的n個元素中大于等于參數(shù)k的值的元素個數(shù)并返回。 2. bool sg(int x) /x為大于

17、等于2的整數(shù) int a=int(sqrt(x); /sqrt(x)為求x的平方根 int i=2; while(ia) return true; else return false; 函數(shù)功能:判斷x是否為一個素數(shù)(或質數(shù)),若是則返回真,否則返回假。 3. 假定結構類型worker中的name域表示姓名,age域表示年齡,pay域表示工資。 void qa(worker a, int n) for(int i=0; ai.ageai.pay; 函數(shù)功能: 從鍵盤上輸入n個worker結構類型的記錄依次保存到一維數(shù)組a的對應元素中。 五、按題目要求編寫函數(shù)(6分) 假定函數(shù)聲

18、明為“void print(int a, int n);”,在函數(shù)體中按下標從大到小的次序輸出數(shù)組a中的n個元素的值,并要求每行輸出6個元素,當然最后一行可以不足6個。答: void print(int a, int n) int i,j=0; for(i=n-1; i=0; i-) coutai ; if(+j%6=0) coutendl; coutendl; 訓練第三套 一、單選題(每小題2分,共20分) 1. 由c+源程序文件編譯而成的目標文件的缺省擴展名為( a )。 a. obj b. lik c. exe d. cpp 2. 程序運行中需要從鍵盤上輸入多于一個數(shù)據(jù)時,各數(shù)據(jù)之間應使

19、用( d )符號作為分隔符。 a. 空格或逗號 b. 逗號或回車 c. 逗號或分號 d. 空格或回車 3. 設x是一個bool型的邏輯量,y的值為10,則表達式 x & y的值為( c )。 a. 1 b. 0 c. 與x值相同 d. 與x值相反 4. for語句能夠被改寫為( d )語句。 a. 復合 b. if c. switch d. while 5. 在下面的do循環(huán)語句中,其循環(huán)體被執(zhí)行的次數(shù)為( a )。 int i=0; do i+; while(i*i10); a. 4 b. 3 c. 5 d. 2 6. 在下面的一維數(shù)組定義中,( c )語句有語法錯誤。 a. int a=1

20、,2,3; b. int a10=0; c. int a; d. int a5; 7. 下面的( c )保留字不能作為函數(shù)的返回類型。 a. void b. int c. new d. long 8. 下面的函數(shù)聲明中,( b )是“void bc(int a, int b);”的重載函數(shù)。 a. int bc(int x, int y); b. void bc(int a, char b); c. float bc(int a, int b, int c=0); d. int bc(int a, int b=0); 9. 當類中一個字符指針成員指向具有n個字節(jié)的存儲空間時,它所能存儲字符串的

21、最大長度為( c )。 a. n b. n+1 c. n-1 d. n-2 10. 假定ab為一個類,則該類的拷貝構造函數(shù)的聲明語句為( d )。 a. ab&(ab x); b. ab(ab x); c. ab(ab* x); d. ab(ab&); 二、填空題(每小題2分,共20分) 1執(zhí)行“cout5的相反表達式為_ x+y=5_。 5. 假定一個二維數(shù)組的定義為“int a36;”,則該數(shù)組含有_18_個元素。 6. 執(zhí)行“typedef int abc20;”語句把abc定義為具有20個整型元素的_數(shù)組類型_。 7假定p所指對象的值為36,p+1所指對象的值為49,則*+p的值為_4

22、9_。 8. 假定a是一個一維數(shù)組,則ai的指針訪問方式為_*(a+i)_。 9對一個類中的數(shù)據(jù)成員的初始化可以通過構造函數(shù)中的初始化表實現(xiàn),也可以通過構造函數(shù)中的_函數(shù)體_實現(xiàn)。 10當一個類對象離開它的作用域時,系統(tǒng)將自動調用該類的_析構函數(shù)_。 三、寫出下列每個程序運行后的輸出結果(每小題6分,共30分) 1. #include #include int sd(int a, int b, char op) switch(op) case +: return a+b; case -: return a-b; default: cout操作符op出錯,退出運行!;exit(1); void

23、main() int x=20, y=6; coutsd(x,y,+) sd(x,y,-)endl; 運行結果:26 14 2. #include #include void main() char* a5=student,worker,cadre,soldier,apen; char *p1; p1=a0; for(int i=1;i0) p1=ai; coutp1endl; 運行結果:worker 3. #include int wf(int x, int y) x=x+y; y=x+y; return x+y; void main() coutwf(8,5)endl; 運行結果:31 4

24、. #include const int n=9; void main() int an=2,4,6,8,10,12,14,16,18; int s=0; for(int i=0; in; i+) if(i%3=0) s+=ai; cout”s=”sendl; 運行結果:24 5. #include void main() int* d=new int5; int i; for(i=0;i5;i+) di=2*i+1; coutdi ; coutx; y+=x*x; while(-n0); return y; 函數(shù)功能:求出從鍵盤上輸入的n個整數(shù)的平方和并返回。 2. bool we(int

25、a, int b, int n) for(int i=0;in;i+) if(ai!=bi) break; if(i=n) return true; return false; 函數(shù)功能:判斷具有n個元素的兩個數(shù)組a和b中對應元素值是否全部相等,若是則返回真,否則返回假。 3. void lk(int a, int n, int& m) float s=0; int i; for(i=0;in;i+) s+=ai; s/=n; m=0; for(i=0;i=s) m+; 函數(shù)功能:統(tǒng)計出數(shù)組a的前n個元素中大于等于其平均值的元素個數(shù)并由引用參數(shù)m帶回。 五、按題目要求編寫函數(shù)(6分) 假定一個

26、函數(shù)聲明為“void ad(int a, int n);”,要求把數(shù)組a中的n個元素值按相反的次序仍保存在數(shù)組a中。答: void ad(int a, int n) for(i=0; in/2; i+) int x=ai; ai=an-1-i; an-1-i=x; 訓練第四套 一、單選題(每小題2分,共20分) 1. c+程序的基本功能模塊為( d )。 a. 表達式 b. 標識符 c. 語句 d. 函數(shù) 2. 存儲以下數(shù)據(jù),占用存儲字節(jié)最多的是( a )。 a. 0 b. 0 c. ”0” d. n 3. 在下面的一維數(shù)組定義中,有語法錯誤的是( c )。 a. int a=1,2,3; b

27、. int a10=0; c. int a; d. int a5; 4. 在下面的語句或語句組中,( b )不正確。 a. int a5; b. int m=10; int am; c. int a=1,5,10,45; d. const int n=12; int an; 5c+語言中的每條簡單語句以_b_作為結束符。 a. 逗號 b. 分號 c. 空格 d. 換行符 6. 含隨機函數(shù)的表達式rand()%20的值在( c )區(qū)間內。 a. 119 b. 120 c. 019 d. 020 7. 當處理一個特定的問題時,若循環(huán)次數(shù)已知,則通常采用( a )來解決。 a. for循環(huán) b. w

28、hile循環(huán) c. do循環(huán) d. switch語句 8. 在下面循環(huán)語句中內層循環(huán)體s語句的執(zhí)行總次數(shù)為( d )。 for(int i=0; in; i+) for(int j=i; jy的邏輯值為_假(false 或0)_。 6假定一個一維數(shù)組的定義為“char* a8;”,則該數(shù)組所占用存儲空間的字節(jié)數(shù)為_32_。 7. 假定x=10,則表達式2+x+的值為_12_。 8假定p所指對象的值為25,p+1所指對象的值為46,則*p+的值為_25_。 9. 假定要動態(tài)分配一個類型為worker的具有n個元素的數(shù)組,并由r指向這個動態(tài)數(shù)組,則使用的語句為worker* r=_ new wor

29、kern;_。 10. 設px指向一個類的動態(tài)分配的對象,則執(zhí)行“delete px;”語句時,將自動調用該類的_析構函數(shù)_。 三、寫出下列每個程序運行后的輸出結果(每小題6分,共30分) 1. #include void sb(char ch) switch(ch) case a: case a: coutwell! ; break; case b: case b: coutgood! ; break; case c: case c: coutpass! ; break; default: coutbad!;break; void main() sb(a); sb(c); sb(b); co

30、utendl; 運行結果:well! pass! good! 2. #include void main() int a6=36,25,48,14,55,40; int b1=a0; for(int i=1;ib1) b1=ai; cout”b1=”b1endl; 運行結果:55 3. #include void main() int a9=3,5,7,9,11,13,15,17,25; int *p=a; for(int i=0;i9;i+) if(i+1)%3=0) cout*(p+i) ; coutendl; 運行結果:7 13 25 4. #include int* lg(int m)

31、 int* a=new intm; for(int i=0;im;i+) ai=3*i+1; return a; void main() int* b=lg(5); for(int i=0;i5;i+) coutbi ; coutendl; deleteb; 運行結果:1 4 7 10 13 5. #include #include struct worker char name15; /姓名 int age; /年齡 float pay; /工資 ; void main() worker x; strcpy(, weirong); x.age=45; x.pay=1235; co

32、 x.age x.payb) a=b; if(ac) a=c; return a; 函數(shù)功能:求出a,b,c三個數(shù)中的最小值并返回。 2. double wa(int a, int n) double s=0; for(int i=0;in;i+) s+=ai; return s/n; 函數(shù)功能:求出數(shù)組a中n個元素的平均值并返回。 3. double sf(double x, int n) /n為大于等于0的整數(shù) double p=1,s=1; for(int i=1;i=n;i+) p*=x; s+=p/(i+1); return s; 函數(shù)功能:計算出表達式的值并返回。

33、五、按題目要求編寫函數(shù)(6分) 假定一個函數(shù)聲明為“int ff(int a, int n);”,要求遞歸求出數(shù)組a中所有n個元素之積并返回。答:int ff(int a, int n) if(n=1) return an-1; else return an-1*ff(a,n-1); /或者if(n=0) return 1; / else return an-1*ff(a,n-1);if we dont do that it will go on and go on. we have to stop it; we need the courage to do it.his comments c

34、ame hours after fifa vice-president jeffrey webb - also in london for the fas celebrations - said he wanted to meet ivory coast international toure to discuss his complaint.cska general director roman babaev says the matter has been exaggerated by the ivorian and the british media.blatter, 77, said:

35、 it has been decided by the fifa congress that it is a nonsense for racism to be dealt with with fines. you can always find money from somebody to pay them.it is a nonsense to have matches played without spectators because it is against the spirit of football and against the visiting team. it is all nonsense.we can do something better to fight racism and discrimination.this is one of the villains we have today in our game. but it is only with harsh sancti

溫馨提示

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

評論

0/150

提交評論