![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
2008秋江蘇計(jì)算機(jī)c++試題試卷 |
21 以下關(guān)于邏輯運(yùn)算的描述中,正確的是_______ A.所有的邏輯運(yùn)算都是雙目運(yùn)算,其優(yōu)先級(jí)相同 B.邏輯運(yùn)算中存在雙目運(yùn)算和單目運(yùn)算,其優(yōu)先級(jí)相同 C.所有的邏輯運(yùn)算都是雙目運(yùn)算,其優(yōu)先級(jí)各不相同 D.邏輯運(yùn)算中存在雙目運(yùn)算和單目運(yùn)算,其優(yōu)先級(jí)各不相同 22.對(duì)于while和do…while循環(huán)語(yǔ)句,以下描述正確的是: 。 A.do…while語(yǔ)句中的循環(huán)體至少執(zhí)行一次 B.兩個(gè)語(yǔ)句中的循環(huán)體可能都不執(zhí)行 C.while語(yǔ)句中的循環(huán)體至少執(zhí)行一次 D.兩個(gè)語(yǔ)句中的循環(huán)體至少執(zhí)行一次 23.以下說(shuō)明語(yǔ)句中,不存在語(yǔ)法錯(cuò)誤的是 。 A.char sl[4]={"a","b","c"}; B.char s2[4]={'a','b'}; C.char s3[]={'I am a student'};D.char s4[14]={"I am a student"}; 24.設(shè)變量a,b,c為整型變量,以下選項(xiàng)中存在語(yǔ)法錯(cuò)誤的是 。 A.c=a+++b: B.c=a+b++; C.c=b++=c++; D.c=++a=b++; 25.設(shè)有程序段: x=-1: if(a!=0){if(a>0) x=1;}else x=0; 該程序段表示的數(shù)學(xué)函數(shù)關(guān)系是 。 26.以下關(guān)于兩個(gè)同類型指針變量的敘述中,在一定條件下,運(yùn)算結(jié)果沒(méi)有實(shí)際意義的是 A.兩個(gè)指針變量可以互相賦值 B.兩個(gè)指針變量進(jìn)行比較運(yùn)算 C.兩個(gè)指針變量進(jìn)行減法運(yùn)算 D.兩個(gè)指針變量進(jìn)行加法運(yùn)算 27.下列有關(guān)構(gòu)造函數(shù)的敘述中正確的是( ) 。 A.類的構(gòu)造函數(shù)不能重載 B.任何一個(gè)類必定有構(gòu)造函數(shù) C.可以定義沒(méi)有構(gòu)造函數(shù)的類 D.任何一個(gè)類必定有一個(gè)缺省的構(gòu)造函數(shù) 28.C++中運(yùn)算符重載可以改變(28) 。 A.運(yùn)算符的優(yōu)先級(jí) B.運(yùn)算符的結(jié)合性 C.運(yùn)算符實(shí)現(xiàn)的功能 D.運(yùn)算符的操作數(shù)的個(gè)數(shù) 29.以下關(guān)于基類指針和派生類指針的敘述中不正確的是(29) 。 . A.基類指針可以指向它的公有派生類的對(duì)象 B.基類指針可以指向它的多次派生后的派生類的對(duì)象 C.派生類的指針不能指向基類的對(duì)象 D.若基類指針指向派生類的對(duì)象,通過(guò)該基類指針可以訪問(wèn)派生類對(duì)象的所有成員 30.以下關(guān)于友元函數(shù)的敘述中,正確的是 。 A.友元函數(shù)不能訪問(wèn)類的私有成員 B.友元函數(shù)破壞了類的封裝性和隱藏性 c.友元函數(shù)的使用與類的成員函數(shù)相同 D.友元函數(shù)的實(shí)現(xiàn)必須在類的說(shuō)明中定義 二、填空題(請(qǐng)將答案填寫在答題紙的相應(yīng)答題號(hào)內(nèi),每個(gè)答案只占一行) ●基本概念題(共5分) 1.設(shè)有語(yǔ)句: int a=5,b=6,c;c=!a&&b++; 執(zhí)行以上語(yǔ)句后,變量b的值為( )。 2.在定義派生類時(shí),如果沒(méi)有指定基類的派生(繼承)方式,則缺省(默認(rèn))的繼承方式是 ( ) 3.c++中編譯預(yù)處理包括:文件包含、宏和( ) 。 4.要將一個(gè)函數(shù)定義為內(nèi)聯(lián)函數(shù)時(shí),通常在定義函數(shù)時(shí)使用關(guān)鍵字 ( ) 。 5.c++中表達(dá)式"I am a student"的值為該字符串的( ) 。 ●閱讀程序題(共13分) 6.[程序](2分) #include <iostream.h> void f(int a[]) {int t=a[0]; a[0]=a[1];a[1]=t; cout<<a[0]<<'\t'<<a[1]<<'\n'; } void main(void) {int b [2]={300,500}; f(b); cout<<b[O]<<'\t'<<b[1]<<'\n'; } 程序輸出的第一行是(_______) ,第二行是(_________) 7.[程序](2分) #include <iostream.h> int fa(int a) {static int m=1;m=a*m; retum m;} void main(void) {for(int i=2;i<=4;i++) cout<<fa(i)<<'\n';} 8.[程序](2分) #include <iostream.h> int f1(int a[3][3]) {int sum=O; for(int i=0;i<3;i++) for(int j=0;j<3;j++){ if(a[i][j]>O)continue; sum+=a[i][j]; } return sum; } int f2(int a[3][3]) {int sum=0; for(int i=0;i<3;i++) for(int j=O;j<3;j++){ if(a[i][j]<0)break; sum+=a[i][j]; } return sum; } void main(void) {int b[3][3]={{1,2,3},{7,-12,-13},{-20,9,-5}}; int s1,s2; s1=f1(b); s2=f2(b); cout<<s1<<endl; cout<<s2<<endl; } 程序輸出的第一行為 _____ ,第二行為_________。 9.[程序](3分) #include<iostream.h> int f(int x[],int n) {if(n==1)x[n]=3; else x[n]=n+f(x,n-1); cout<<x[n]<<'\n'; return x[n]; } void main(void) {int b[5]={3,4,5,6,0}; f(b,3); for(int i=0;i<5;i++) cout<<b[i]<<'\t'; cout<<endl; } 程序輸出的第一行是() ,第二行是() ,第三行是( )。 10.[程序](2分) #include<iostream.h> class A{ int x; public: A(int a){x=++a;} ~A(){cout<<x<<'\n';} int get(){return x;} }; class B:public A{ int y; public: B(int b):A(b){y=get()+b;} B():A(5){Y=6;} ~B(){cout<<y<<'\n';} }; void main(void) {B b(5); 。 } 程序輸出的第一行是( ) ,第二行是( ) 。 11.[程序](2分) #include<iostream.h> class A{ int x; public: A(int x=0) {this->x=x;} virtual void f(){cout<<x<<endl;} }; class B;public A{ int Y: ’ public: B(int x,int y=1):A(x) {this->y=y;} void f(int a){cout<<y<<endl;} }; void main(void) {A al(10),*pa; B bl(20,30); a1.f(); pa=&a1; pa->f(); pa=&b1; pa->f(); } 程序輸出的第二行是( ) ,輸出的第三行是( ) 。 ●完善程序題(共12分) 12.以下程序的功能是:將兩個(gè)字符串分別輸入到sl和s2中,并使s2中的字符按升序排列 (用函數(shù)sort()實(shí)現(xiàn)排序)。然后,依次從sl中取一個(gè)字符插入到s2中,并使s2中的字符 保持升序。函數(shù)insert(char *p,char c)的功能是將字符c插入到p所指向的字符串中, 使p所指向的字符串保持升序。函數(shù)merge(char *pl,char *p2)依次從p2所指向的字 符串中取出一個(gè)字符,并插入到p1所指向的字符串中。 [程序](4分) #include<iostream.h> #include<string.h> char *sort(char s[]) {int len=strlen(s); for(int i=0;i<len-1;i++) for(int j=i+1;j<len;j++) if( ){ char c=s[i]; s[i]=s[j];s[j]=c; } return s; } void insert(char *p,char c) {char *p1=p; int len=strlen(P); while(*p1<c&&*p1!=0)p1++; char *p2=p+len; while(p2>=p1){ . ( 20 ); p2--; } ( 21 ); } char *merge(char *p1,char *p2) {while(*p2){ _________; p2++; } retum p1; } void main(void) {char sl[100],s2[200],c; cout<<"輸入第一行字符串:";cin.getline(s1,100); cout<<"輸入第二行字符串:";cin.getline(s2,100); cout<<s1<<'\n'<<s2<<'\n'; sort(s2);merge(s2,s1); cout<<s1<<'\n'<<s2<<'\n'; } 13.以下程序中的功能是:通過(guò)重載運(yùn)算符+,-和=,分別實(shí)現(xiàn)一維數(shù)組(向量)的加法(對(duì)應(yīng)元素相加)、減法(對(duì)應(yīng)元素相減)和向量對(duì)象之間的賦值,例如:設(shè)a,b,c是類Arr的對(duì)象,a的成員x[]={1,1,1,1,1,1},b的成員x[]={2,2,2,2,2,2},執(zhí)行:c=a+b后,c的成員x[]={3,3,3,3,3,3} [程序](4分) #include<iostream.h> class Art{ float x[20]; int size; public: Arr(float a[],int n) {for(int i=0;i<n;i++) x[i]=a[i]; size=n; } Arr() {for(int i=O;i<20;i++)x[i]=O; size=0; } Arr operator +(Arr); Arr operator -(Arr); Arr &operator =(Arr&); int GetArr(float y[]) { for(int i=0;i<size;i++)y[i]=x[i]; retum size; } void print() { for(int i=O;i<size;i++) cout<<[i]<<'\t'; cout<<'\n'<<"size="<<size<<'\n'; } }; Arr Arr::operator +(Arr a) {Arr tem; for(int i=0;i<size;i++) ________; tem.size=size; return tem; } Arr Arr::operator -(Arr a) {Arr tem; for(int i=0;i<size;i++) _________ ; tem.size=size; retum tem; } Arr &Arr::operator=(________) {for(int i=O;i<a.size;i++) x[i]=a.x[i]; size=a.size; return (______) ; } void main(void) {float b1[6]={10,20,30,40,50,60}; float b2[6]={100,200,300,400,500,600},b3[6],b416]; Arr al(b1,6),a2(b2,6),a3,a4; a3=al+a2;a4=a2-al; a3.print();a4.print(); int n=a1.GetArr(b3); for(int i=0;i<n;i++)cout<<b3[i]<<'\t'; cout<<'\n'<<n<<'\n'; } 14.下面程序的功能是:首先建立一條鏈表,順序從鏈表中找到data為最大值的結(jié)點(diǎn),從鏈表 中刪除該結(jié)點(diǎn),并將其值返回,最終刪除整個(gè)鏈表,同時(shí)得到按降序排序的數(shù)組x。其中, 函數(shù)Insert(int a,node *head)的功能是:用參數(shù)a產(chǎn)生一個(gè)新結(jié)點(diǎn),將其插入鏈?zhǔn)?/SPAN>,并返 回鏈?zhǔn)字羔槨?/SPAN>DeleteMax(node,*&head)的功能是:從head所指向的鏈表中找到data值為 最大的結(jié)點(diǎn),從鏈表中刪除該結(jié)點(diǎn)并將其結(jié)點(diǎn)值返回。 算法提示:當(dāng)鏈表為空時(shí),返回-1。在查找的過(guò)程中,始終讓pmax指向當(dāng)前data值 為最大的結(jié)點(diǎn),并讓pmax1指向pmax的前一個(gè)結(jié)點(diǎn)。找到data值為最大的結(jié)點(diǎn)后,將其 從鏈表中刪除,并返回其data值。 [程序](4分) #include <iostream.h> struct node{ int data; node *next; }; node *Insert(int x,node *head) {node *p=new node; p->data=x; (_________);head=p; return head; } int DeleteMax(node:I:&head) {node *pl,*p2,*pmax,*pmax1; int max; p1=p2=head: if(!head) return -1; max=p1->data;pmax=p1; while(p1){ if(max<pl->data){ max=p1->data; pmax=pl;pmax1=p2; } p2=p1; (________) ; } if(pmax==head) head=head->next; else (_________) ; delete pmax; retum max; } void main(void) { int a; int x[200],count=0; node *head=0; cin>>a; while(a!=-1){ head=Insert(a,head); cin>>a; } while(head){ x[count]=(_________); count++; } for(int i=0;i<count;i++) cout<<x[i]<<'\t'; cout<<endl; } |