大學C++期末試卷必考試題及答案_第1頁
大學C++期末試卷必考試題及答案_第2頁
已閱讀5頁,還剩3頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、5、離級語言程序設計I試卷(A第3頁共8頁離級語言程序設計I試卷(A 第 頁共8頁第1頁共8頁大學C+期末試卷試題及答案一、單項選擇題(每小題2分,共20分) |、下列合法的變S名S c )0(A) 8d(B) lJ2h(C) jut(D) file, cpp2、有說明語句:int a=0; double x=5. 16;,則以下語句中,(C )屬于編譯錯誤*(A) x=a/x;(B) x=i/a;(C) a=a%x;(D) x=x*a;3、設有:int db=5,c=3, d=l;,則條件表達式 ad?c:d 的值為(A) 7(B) 5(C)3(D) 14、執(zhí)行下列語句后,x的值是(D ).

2、 int x. y ;x = y = 1;+x|+y ;y 的C )(A)不礴定(B) 0(C) 1(D) 25、卜列forift句站環(huán)的次數(shù)B )ofor ( int i=0, x=0; x & i=3i+)(A) 3(B) A int a = 1 ; fun( a*3. 14 ):(C ) int b = 10; fun ( &b );( D ) fun ( 56 );7、關于函數(shù)定義和調(diào)用的說法正確的是 A ).(A)函數(shù)能嵌套調(diào)用.但不能收套定義tB)函數(shù)能嵌fi調(diào)用,也能嵌ft定義C)函數(shù)不能嵌套調(diào)用.也不能嵌套定義D)閑數(shù)不能嵌輕調(diào)川,W能嵌釤定義8、打定義一維數(shù)組講句:int a

3、5,*p,,則卜列衣達式錯誤的足(B )。 A) p=p+l(B) a=a+l ( C ) pa( D ) a+ 29、假定有語句:int b 3 =(,(1,2),1,2.3,0);則b22的偵足(D ).(A)0(B)1(C) 2 D) 310、矜川數(shù)組名作為調(diào)用函數(shù)的實參,則傳遞給形參的圮(A 。(A)數(shù)組存荇地址(B)數(shù)組的第一個元索俏(C)數(shù)組中全部元索的值(D)數(shù)組元索的個數(shù)二、簡答題(共20分)1、有以下循環(huán)Hi句無法正常結(jié)束祕,iff找出原W。(2分int i=100, j=0, m=0,4iile (1) (B+=j: j+; if(j=i) break; 2、一W序求統(tǒng)計未

4、退休(W性年齡60.女性55)職I:中1-3月份出生的人數(shù),消寫出 職工記錄屮結(jié)構(gòu)的W小定義形式.并寫出用于判斷的C+邏鉗農(nóng)達式。(4分struct Employee ( char name20, char sex, int Byear, int Bmonth, int Bday,), Envloyee em,/設男性=m,女性=f (en. sex=F m ft42007-em. Byear60| Iem. sex=/ f Mt2007-ein. Byear55)&(eBL Bmonth=l)3、SA說明inta4*5,兩個表示數(shù)組a最后一個元素地址值的表達式.(3U19a+194、Sff說

5、叫 double x10= 0 * y = new double 10; 問 sizeof (x), sizeof y 的俏丼足多少?并分析結(jié)果原W。(4分sizeof (y)的值為4, y是指針變量.5、S有函數(shù)調(diào)用ifi句 Count (a , n, right, negative);功能Si由參數(shù) right, negative 返冋統(tǒng)計數(shù)組a的n個元索中正整數(shù)和負锫數(shù)的個數(shù)。對吣的函數(shù)原型足什么?(2分) void Count (int *a, int f int&( int&);void Count (int a口,int , int&, intL);6、以F語句不能正確輸出中-向鏈

6、表的數(shù)據(jù)元索依.請找出屁閃* (2分) struct link int data; link next: :link head, *p,pMiead; w4iile (p) cout void mainO int i, s = 0; i=4; i6; i+ ) switch ( i ) case 3:s +二 i*i;break.case 4:s += i*i;break.case 5:s += i*i;break;default:s += 2:)cout s endl;S=16S=41#include void main 0 int i, j;for ( i=l; i=3, i+ ) j=l

7、:while (ji) (cout i,t* jendl; j+;)2 13132#include void func(int, int, int *); void mainO(int x. y, z ;func(l, 2, &x); func (3, x, &y); func (x, y, &z); coutxendlyendlzendl ; void func (int a, int b, int *c) b-=a :*c=ba;)4、#include int fl (int a, int b) return a%b*5;) int f2(int a,int b) return a*b,)

8、int f3(int (*t) (int, int), int a. int b) return (*t) (a. b);) void mainO(int (*p)(int, int);p=fl : coutf3(p, 5, 6)endl ; P=f2 ; coutf3(p, 7, 8)endl ;2556#include#includevoid fNum (int(int i;if(w0) for(i=l;i=w; i+) coutsetw(3)w coutc & b+ca & c+ab ) ( if ( Lil) a=b Mt b=ccout等邊三角形! n: else if ( (2J)

9、a=b 11a=c11b=ccout等腰三角形! n; else cout其它三角形! n*; ) else cout不能構(gòu)成三角形! n; 2、以卜程序功能足輸出1000以內(nèi)個位數(shù)為6 h.能被3整除的所有數(shù)。諸瑣空。 #include void main () int i, j : for ( i=0 : : i+ )i 100(j = i 10 + 6 ;if ( 【4】 ) continue ;j % 3cout j :離級語言程序設計I試卷(A 第 頁共8頁,3+(n-3),1#include#include#includeint ispr ime (int);void mainO

10、(int num:cout=6) An: cinnumfor(int n=6z n=num, n+=2)Hfor(int i=3;i=n/2;i+=2)if( 5 ) isprime(i) & isprime(nMi) (coutsetw(3Xn,=setw(3)i,* + setw(3) (ni)endl; break ;)int ispr ime (int n) (int it sqrtm=(int)sqrt (n); for(i=2; i=sqrtm; i+) if ( 6 ) return 0 ; n%i=O 【7】 ; return 11、以卜松印足創(chuàng)讓-個動態(tài)數(shù)組.數(shù)31長度山序運

11、行時輸入數(shù)據(jù)決定。調(diào)川隨機函數(shù)對動態(tài)數(shù) 組賦初位,并輸出動態(tài)數(shù)組元家位。請?zhí)?。 #inc lude #include #include void main 0 (int n, *p= L8 ;NULLcout n; P= 【9】 new intnif(p=NULL) coutAllocation faiure n*; return; srand (time (0): for( int i=0; in; i+ ) pil =rand()%100; for ( 【10】 : ap+n; a+ ) int *a=p離級語官程序設計I試卷(A) 第5頁共8頁 cout*af t :) coutend

12、l delete p; 五、編程題(20分1、Vine ludeionanip. void main 0 int a.b;couta;coutb;coutsetw(12)*!Tsetw(12)* 平方setw12)* 立方 *endl; for(int i=a; i=b; i+)coutsetw(12)isetw(12)i*isetw(12)i*i*iendl; )2、(6分)以Eft!序用隨機函數(shù)生成兩位數(shù),収M個各不相等的數(shù)據(jù),按生成顧序存放/I:數(shù)組a屮。閣3足生成20個數(shù)據(jù)的砧示效果.消依題點編寫函數(shù)insert及瑣寫函數(shù)職型。#include #include #includeint

13、 insert (int *ap, int kj int n): 成:E:C+ + CC+f 題卷壬羅組:346 80111?95129954469096693663394964W3生成tt泔/函數(shù)原型?920int insert (int ap, int k, int n):void mainO(const int M=20:int n, i=0,int aM = (0),srand(time (0); 湳ile (iM) don=rand()%100; while (n10):/生成&裾if (insert (a, i, n) )/把不相同數(shù)據(jù)插入數(shù)組ai+;cout* 生成數(shù)組:?,en

14、dl;for(i=l; i=M;i+)(coutai* *; if(i%10=0)coutendl; coutendlint insert (int *ap, int k, int n)I for (int j=0; jk; j+)/雄去相同數(shù)if(apj=n) break;if (j=k) (apjRi: return 1; /添加數(shù)據(jù) return 0;3、(8分)本S序功能足把-個用拼音輸入的名字fl動生成6位數(shù)字串的密碼。生成規(guī) 則足把字母串的最后6位逆序.取毎個字母小寫的ASCII碼值.其除以10的余數(shù)為該位的 密碼值。當輸入名字的字母串不足6位,生成時以字母補足 M4是程序的運行效

15、果、W填寫change成數(shù)的娥數(shù)原甩并編寫函數(shù)。#include1idi x入名芊折曾,以宋:1ZhonqFuwatt生成密碼為:an9 kev to continue#includestruct link (char s; link next;); void inputName (link *4 h); void outLink(link *h),/ / change 的函數(shù)原型void main ()(link *name=NULL. *code=NULL; coutCW輸人名字拼育,以#結(jié)束:n inputName (name),change (code, name);cout (ps):*4iile (p-s=,a* &p-ss= A* &p-snext=h; h=p;p=new link; cin(ps);void change (link fithCode, link h) char d;

溫馨提示

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

最新文檔

評論

0/150

提交評論