![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
江蘇計算機(jī)等級vc++2008春試題 |
第二部分Visual C++程序設(shè)計 ’ 一、選擇題(用答題卡答題,答案依次填在答題號內(nèi)) 21•下列關(guān)于switch語句的描述中正確的是(21) 。 A•switch語句中的default子句可以沒有,也可以有多個 B•switch語句中的每個子句中必須有break語句 c•switch語句中的default子句只能放在最后 D.switch語句中的case子句后面的表達(dá)式只能是整型表達(dá)式 22•下列函數(shù)原型說明中,錯誤的是 (22) 。 A•int &fl(); B.int f2(double =5); C•void f3(void (*p)()); D.int f4(int a=O,int b); 23.設(shè)有說明語句; float y=5.16347;int x; 則以下表達(dá)式中,可以實現(xiàn)將y中的數(shù)值保留小數(shù)點后兩位,第三位四舍五入的表達(dá)式是 A.y=(y*100+0.5)/100.0 B.x=y*100+0.5,y=x/100.0 . C.y=y*100+0.5/100.0 D.y=(y/100+0.5)*100.0 24.設(shè)有說明語句; char s[80]="Hello";int a[20]={1 2}; 下列選項中,存在語法錯誤的是 (24) 。 A.cin>>s; B.cout<<s; C.cin>>a; D.cout<<a; 25•下列關(guān)于new運算符的敘述中不正確的是(25) 。 A•使用運算符new創(chuàng)建對象時必須定義初始值 B•使用運算符new創(chuàng)建對象時會調(diào)用類的構(gòu)造函數(shù) C•運算符new可以用來動態(tài)創(chuàng)建對象和對象數(shù)組 2•使用new運算符創(chuàng)建的對象可以使用運算符delete撤銷 26•若有說明語句; int s[4][6],t[6][4],(*p)[6]; 則以下選項中正確的是 ( 26 ) 。 A.p=t B.p=s c.p=s[0]; D.p=t[0]; 27.以下敘述中不正確的是 (27) A•在函數(shù)內(nèi)的復(fù)合語句中定義的變量在本函數(shù)范圍內(nèi)有效 B•形式參數(shù)是局部變量 C•在函數(shù)內(nèi)定義的變量只在本函數(shù)范圍內(nèi)有效 O•在不同函數(shù)中可以使用相同名字的變量 28•以下有關(guān)抽象類的敘述中不正確的是 (28) . A.抽象類至少含有一個純虛函數(shù) B.抽象類至少含有一個沒有函數(shù)體的虛函數(shù) c.在抽象類的派生類中可以據(jù)供純虛函數(shù)的實現(xiàn)代碼 D.可以說明抽象類的對象 29.下列關(guān)于構(gòu)造函數(shù)的描述中不正確的是 A.構(gòu)造函數(shù)可以設(shè)置缺省參數(shù) B.構(gòu)造函數(shù)在定義類的對象時自動執(zhí)行,但不用顯示調(diào)用 C.構(gòu)造函數(shù)可以對靜態(tài)數(shù)據(jù)成員進(jìn)行初始化 D.構(gòu)造函數(shù)可以重載 30.設(shè)有類定義: class B{ public: void G(float x=O){cout<<x<<endl;} void G(double x){cout<<x<<endl;} } r; 則以下選項中存在語法錯誤的是_____ A.r.G(); B.r.G(10); C.r.G(3.14); D.r.G( 二、填空題(請將答案填寫在答題紙的相應(yīng)答題號內(nèi),每個答案只占一行) •基本概念題(共5分) 1.在構(gòu)造函數(shù)和析構(gòu)函數(shù)中,可以定義為虛函數(shù)的是________。 2• 若有說明語句: float a[]={1,2,3,4,5}; int b=&a[3]-&a[0]; 則執(zhí)行以上語句后,b的值為_______ 3.在C++中,重載賦值運算符"="只能用______函數(shù)實現(xiàn),而重載插入運算符"<<"和提取 運算符">>"只能用_______函數(shù)實現(xiàn) 4.設(shè)e是表達(dá)式,其類型可以是:float、double、int、char、enum,C++中規(guī)定,在開關(guān)語句 switch(e)中,e的值類型不能是________ ●閱讀程序題(共13分) 5.[程序](2分) #include <iostream.h> int fun(int); void main(void) { int a=2; for(int i=O;i<3;i++) cout<<fun(a++)<<endl; } int fun(int a) {int b=0; static int c=3; return(b++,c++,a+b+c); } 程序輸出的第二行是( ) ,第三行是( ) 。 6.[程序](2分) #include<iostream.h> void ff(int &m,int &n) {int t=m+n; m=n; n=t; } void main(void) {int a,b,i; for(a=b=i=1;i<=5;i++){ ff(a,b); cout<<a<<'\t'<<b<<endl; } } 程序輸出的第二行是( ) ,第四行是( ) 7.[程序](2分) #include <iostream.h> void f1(int n,int &i,char s[]) {s[i]='0'+n%10; n=n/lO; i++; if(n==0)s[i]=0; else f1(n,i,s); } void f2(int n,int i,char s[]) {if(n){ int k; k=n%10: f2(n/lO,i+1,S); s[i]='0'+k; } } void main(void) {char s[20]; int i=0; f1(24675,i,s); s[i]=0; cout<<"s="<<s<<end1; static char s1[20]; f2(1357,0,s1); cout<<"s1="<<s1<<end1; } ' 程序輸出的第一行是( ) ,第二行是( )。 8.[程序](2分) #include <iostream.h> char *f(char *s1,char *s2) {char *p,*p1; int n=0; while(*(s1+n))n++; char *buf=new char[n+1]; p=buf;p1=s1; while(*p++=*p1++); p=s1:p1=s2; while(*p++=*p1++); cout<<buf<<endl; p--;p1=buf; whi1e(*p++=*p1++); de1ete []buf; return s1; } void main(void) {char s1[30]="about ",s2[]="time "; cout<<f(s1,s2)<<endl; } 程序輸出的第一行是______ ,第二行是_______。 9.[程序](3分) #include<iostream.h> int fun(int x,int y) { cout<<x<<'\t'<<y<<endl; return(x>y?x:y); } void main(void) {int a=3,b=6,k=4,m; m=fun(fun(a,b),fun(b,k)); cout<<"m="<<m<<endl; } 程序輸出的第一行是_____,第三行是______,第四行是________ 。 lO.[程序](2分) #include <iostream.h> class Base {public: void virtual f(){cout<<"Base::f()"<<endl;} void virtual g(){cout<<"Base::g()"<<endl;} }; class A:public Base {public: void f(int a=O){cout<<"A::f()"<<endl;} }; class B:public A { void f(){cout<<"B::f()"<<endl;} void g(){cout<<"B::g()"<<endl;} }; void main(void) { B b; Base *p=&b; A *q=&b; P->f();p->g(); q->f();q->g(); } 程序輸出的第一行是( ) ,第三行是( ) 。 完善程序題(共12分) 11.下面的程序功能是:將一個字符串中的單詞分行輸出。例如,對字符串:"What is your name?",執(zhí)行程序后,輸出結(jié)果為 What is your name? [程序](4分) #include <iostream.h> char *nextWord(char **pp) {static char word[81]; while(**pp=='') _______; char *pw=word; while(**pp&&**pp!=' ') *pw++=*(*pp)++; _______ ; return ______ ; } void main(void) {char s[]="What is your name?",*ps=s; do{cout<<nextWord(_________)<<endl; } 12.以下程序的功能是:二維數(shù)組a中每列元素都是從小到大有序排列的,將一維數(shù)組b中的 元素依次插入到數(shù)組a的每列中,并保持a中每列數(shù)據(jù)的有效性,最后將執(zhí)行插入操作 后的數(shù)組a以矩陣形式輸出。例如: 原數(shù)組 1 3 2 1 3 1 4 6 8 2 6 2 8 9 10 數(shù)組b為{2 7 1}操作后的數(shù)組a為:4 7 8 8 9 10 [程序](4分) #include <iostream.h> #include <iomanip.h> #define ROW 4 #define COL 3 void f(int a[][COL],int b[]) {int i,j; for(_________ ){ for(j=ROW-1;j>0;j--) if(a[j-1][i]>b[i]) (24) ; else break; (______) ; } } void main(void) {int a[ROW][COL]={1,3,2,4,6,8,8,9,10}; int b[COL]={2,7,1}; cout<<"插入前數(shù)組中的數(shù)據(jù)依次為:"<<'\n'; for(int i=0;i<ROW-1;i++){ for(int j=0;j<COL;j++)cout<<setw(5)<<a[i][j]; cout<<endl; } cout<<endl: __________; cout<<"插入后數(shù)組中的數(shù)據(jù)依次為:"<<'\n'; for(i=0;i<ROW;i++){ for(int j=0;j<COL;j++) cout<<setw(5)<<a[i][j]; cout<<endl; } } |