同濟大學(xué)c++C卷答案_第1頁
同濟大學(xué)c++C卷答案_第2頁
同濟大學(xué)c++C卷答案_第3頁
同濟大學(xué)c++C卷答案_第4頁
全文預(yù)覽已結(jié)束

下載本文檔

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

文檔簡介

1、同濟大學(xué)課程考核試卷課號:課名:C+語言考試考查:考查此卷選為:期中考試(卜期終考試(,)、重考()試卷年級 專業(yè) 學(xué)號 姓名 得分一、選擇填空(30分)1)按照標識符的要求,下列符號中不屬于標識符組成部分白是(D )。A、大小寫字母已數(shù)字C、下劃線D ! # $ % A & *2) 若有定義:char c;int x;float y;double z;則表達式x+c-(int)z/y 值的類型為( C )。A、char B 、int C 、float D 、double3)有下列定義:char s10,*p,s1口="xyz" ;以下語句中正確的是( B )。A、

2、s = "abcdefgh“ ; B、p = "abcdefgh”;C、s = s1;Ck p=&s; cin >> p;4)以下數(shù)組定義中正確的是( C )。A、int n=5;int an;B 、int b3=1,2,3;C、int c34=0; D 、int d口尸2,4,6,8;5)已知 int a(5),b(3);當邏輯表達式語句!a&&b+;b|a-|a+b;執(zhí)行完畢后,a和b的值分別為( D )。A、4,4 B、4,3 C、5,4 D、5,36)以下常量中不是字符型常量的是( B )。A、101 B、"a"

3、;C、+'D、h'7)對于int *p(); 的描述,(B )是正確的。A、定義一個指向某int型函數(shù)的指針變量p。B、函數(shù)p的聲明,該函數(shù)的返回值是一個指向整型數(shù)據(jù)的指針值。C、定義函數(shù)p,函數(shù)p的返回值為int型數(shù)據(jù)。D、定義一個int型指針變量p,指向int型數(shù)據(jù)。8)下列變量定義中,不正確的是( D )。A、int a(0),b=1;B> int a,&b=a ;C、int a,*b=&a ; D int a=b=1 ;9)有下列定義:int c10; int *p;以下執(zhí)行語句中不能使數(shù)組c中元素c1的值為1的是(C )。A、*(c+1)=1;B

4、、p=c; *(p+1)=1;C、* +c =1;D、p=c; * +p =1;10)當被調(diào)函數(shù)的形參是數(shù)組,調(diào)用函數(shù)的實參用 數(shù)組名相對應(yīng),實現(xiàn)函數(shù)調(diào)用時,下列描述中,(B )是錯誤的:A、實參數(shù)組把地址值傳遞給形參數(shù)組,使得兩者 指向內(nèi)存的同一片存儲域;B、函數(shù)調(diào)用時系統(tǒng)將實參數(shù)組元素拷貝一個副本 給形參數(shù)組;C、若實參是一維數(shù)組名,其對應(yīng)的一維形參數(shù)組 可以不必說明數(shù)組大小,只需在數(shù)組名后跟一對說明即可,但兩者類型應(yīng)保持一致;D、在被調(diào)函數(shù)中對形參數(shù)組的任何改變,會影響 實參數(shù)組所指內(nèi)存存儲單元中的內(nèi)容。11)在下列關(guān)鍵字中,用以說明類中公有成員的是(A ):A、publicB、priv

5、ateC、protectedD、friend12)以下關(guān)于構(gòu)造函數(shù)特征描述中,( D )是不正確的:A、構(gòu)造函數(shù)的函數(shù)名與類名相同;B、構(gòu)造函數(shù)允許重載;C、構(gòu)造函數(shù)可以設(shè)置缺省參數(shù);D、構(gòu)造函數(shù)必須指定其函數(shù)類型說明。13)下面關(guān)于對象概念的敘述中,(A )是錯誤的。A、對象就是結(jié)構(gòu)體變量;B、對象代表正在創(chuàng)建的系統(tǒng)中的一個實體;C、對象是一個狀態(tài)和操作(或方法)的封裝體;D、對象之間的信息傳遞是通過發(fā)送消息進行的。14)在私有繼承中,基類的公有成員將成為其派生 類的(C )成員。A、公有 B 、保護 C、私有 D、friend15) 設(shè) Date 是一個日期類,date1 是該類的一個對象

6、, p 是指向 date1 的 Date 類指針,GetDate()是 Date 類的一個公有成員函數(shù),則以下不正確的表達式是(A ) 。A、 Date.GetDate()B、 date1.GetDate()C、 (*p).Date:GetDate()D、 p->GetDate()二、寫出下列各程序運行時的輸出結(jié)果(50 分 )1.#include <iostream.h>void main() int i=10,j;float a;j = 1/(10/3); a = i/3.0;cout << j << endl;cout << a &l

7、t;< endl;答: 03.333332.#include <iostream.h>void main( ) int i,j;i=j=2;if(i=1)if(j=2)cout << (i,i+j) << endl; elsecout << (i=i-j) << endl;cout << i <<“” << j << endl;答: 31 23.#include <iostream.h>void swap(int &x,int y) int t=x;x=y;y=

8、t; void main( ) int a=10,b=15;swap(a,b);cout<< “ a=” <<a<<“ b= ” <<b<<endl;答: a=15 b=154.#include <iostream.h>int x=1;void fun(int *p) static int x=2;*p *=x-1;x += 2; void main( ) int i;for(i=1;i<4;i+) fun(&x);cout << x << endl; 答: 135. 15#inclu

9、de <iostream.h>void f(char *p,int n) int i;for(i=0;i<n;i+) cout << *(p+i);void main( ) char s=“ 0123456789ABCDE”F ;f(s+8,5);答: 89ABC6.#include <iostream.h>void main( ) int x(5);do switch(x%2) case 1: x-;break;case 2: x+;break;x-;cout << x << endl;while(x>0);答: 31-

10、17.#include <iostream.h>void f(int *p,int n)for(int i=0;i<n;i+) pi=i+1; void main( )int a33,i,j;f(a0,9);for(i=0;i<3;i+) for(j=0;j<3;j+)cout<<aij<<cout << endl; 答: 1 2 34 5 67 8 98.#include <iostream.h>void main( ) int a34= 1,2,3,4,5,6,7,8,9,10,11,12;int *p13=a0

11、,a1,a2;int (*p2)4=a;int *p=&a00;cout << *(p+1) << endl;cout << *(p11+2) << endl;cout << *(*(p2+2)+3) << endl;答: 27129.#include <iostream.h>class TPoint public:TPoint( )x=0;y=0;TPoint(int i,int j)x=i;y=j;void Display( );private:int x,y;void TPoint:Display

12、( ) cout << x <<“ , ” << y << endl; void main() TPoint p1(4,5),p2,p3(-1,8);p1.Display( );p2.Display( );p3.Display( );答:4, 50,0-1, 810.#include <iostream.h>#include <string.h>class Staffprivate:char name32;float wage,tax,wAfterTax;public:void SetData(char *s,float

13、w) strcpy(name,s); wage = w; void Show() cout << name << endl;cout << wage << " "cout << tax << " "cout << wAfterTax << endl; void TaxCalc();else if(wage < 5000) p=0.1;else p=0.15;tax = p * wage;wAfterTax = wage - tax;void main(

14、)int i;Staff st3,*p;st0.SetData("Zhang",1800);st1.SetData("Wang",4000);st2.SetData("Zhao",6000);p=st;for(i=0;i<3;i+)(p+i)->TaxCalc();for(i=0;i<3;i+) (p+i)->Show();答: Zhang1800 90 1710Wang4000 400 3600Zhaovoid Staff:TaxCalc() float p;if(wage < 1000.0) p=0.

15、0;else if(wage < 2000) p=0.05;6000 900 5100三、編程(20分)1)某班有30個學(xué)生,5門功課。試根據(jù) sort函 數(shù)的原型聲明,寫出按學(xué)生課程總分由高到低進行 排序的sort函數(shù)程序。#include <iostream.h>#include <stdio.h>struct student int num;char name32;float score5;float total;/ 總分;void sort(student *p,int n);/sort函數(shù)的原型聲明,其中: n為學(xué)生數(shù)void main() studen

16、t stu30;int i,j;float sum;for(i=0;i<30;i+) cin >> stui.num;gets();sum = 0.0;for(j=0;j<5;j+) cin >> stui.scorej;sum += stui.scorej; stui.total = sum;sort(stu,30);for(i=0;i<30;i+) cout << stui.num << endl;cout << << endl;for(j=0;j<5;j+

17、)cout<<stui.scorej<< " ” ; cout << stui.total << endl;/ sort函數(shù)程序?qū)懺谙旅婵瞻滋巚oid sort(student *p,int n)int i,j,k;student temp;for(i=0;i<n-1;i+) k=i;for(j=i+1;j<n;j+)if(p+k)->total<(p+j)->total) k=j;if(i!=k) temp=*(p+i);*(p+i)=*(p+k);*(p+k)=temp; 2)根據(jù)MyStr類中成員函數(shù) Replace函數(shù)的原型聲 明,寫出將 MyStr類對象s中所有出現(xiàn)字符 c1的地方均替換為字符c2的Replace函數(shù)。#include <iostream.h>#include <string.h> class MyStr private:char str80;public:MyStr(char s)strcpy(str,s); void Print()cout << str << endl; void Replace(char c1,char c2

溫馨提示

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

評論

0/150

提交評論