清華大學(xué)計(jì)算機(jī)系C++期末考試題及答案_第1頁
清華大學(xué)計(jì)算機(jī)系C++期末考試題及答案_第2頁
清華大學(xué)計(jì)算機(jī)系C++期末考試題及答案_第3頁
已閱讀5頁,還剩3頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、清華大學(xué)計(jì)算機(jī)系 C+期末考試題及答案一、 填空題(25 小題,共 50 分)(以下每小題 1 分,共 10 分)C+中,函數(shù)的參數(shù)有兩種傳遞方式,它們是值傳遞和 地址或指針或引用傳遞。當(dāng)一個(gè)成員函數(shù)被調(diào)用時(shí),該成員函數(shù)的 this 指針 指向調(diào)用它的對(duì)象。3字的數(shù)據(jù)成員進(jìn)行訪問時(shí),如果沒有 作用域分隔符限定時(shí) ,對(duì)此數(shù)據(jù)成員的訪問將出現(xiàn)歧義。引用 作為參數(shù)初始化創(chuàng)建中的對(duì)象。保持不變 。ABC的表達(dá)式為 AB|Ac&b=c的值是 0 。(以下每小題 2 分,共 20 分)抽象、封裝、 繼承 、 多態(tài) 。在Visual 不同 。、 析構(gòu)函數(shù)沒有參數(shù) 、析構(gòu)函數(shù)可以定義為虛函數(shù) 。動(dòng)態(tài)聯(lián)編要滿足

2、兩個(gè)條件,它們是 。在C+類中,有一種不能定義對(duì)象的類,這樣的類只能被繼承,稱之為抽象類 。在C+constconst對(duì)象不能被修改 。舉出C+類 、 枚舉 。C+字符數(shù)組 0 。C+輸入輸出庫 變量 n 的輸出語句:coutn;舉出C+繼承 、復(fù)用 。(以下每小題 4 分,共 20 分)下面程序的運(yùn)行結(jié)果是 3 #include void main()char a=a,b=j; float x;x=(b-a)/(F-A);printf(%dn,(int)(3.14*x);2 5 8 11 #include iostream.hvoid main( )int i=1;while (i=15)

3、i+;if (i%3!=2) continue;else cout i=iendl;下面程序的運(yùn)行結(jié)果#include iostream.hclass testprivate: int num; float public: test( );int getint( )return num; float getfloat( )return test( );test:test( )cout Initalizing default endl; num=0;fl=0.0;test:test( )cout Desdtructor is active endl;void main( )test array2

4、;cout array1.getint( ) array1.getfloat( ) endl;Initalizing default Initalizing default 0 0Desdtructor is Desdtructor is 下面程序的運(yùn)行結(jié)果#include class Apublic:A()coutA:A() called.n;virtual A()coutA:A() called.n;class B:public Apublic:B(int i)coutB:B() called.n;buf=new chari; virtual B()delete buf; coutB:B(

5、) called.n;private: char ;void fun(A *a)delete a;void main()A *a=new B(15); fun(a);A:A() called.B:B() called.B:B() called.A:A() called.下面程序的運(yùn)行結(jié)果#include int a =1,3,5,7,9;int *p =a,a+1,a+2,a+3,a+4; void main( )printf(%dt%dt%dn,a4,*(a+2),*p1); printf(%dt%dt%dn,*(p+1)+a2,*(p+4)-*(p+0),*(a+3)%a4);9 5 38

6、 4 7二、 問答題(每小題 5 分,共 20 分)能會(huì)產(chǎn)生什么問題?元也復(fù)制過去。這樣,就可能出現(xiàn)同一內(nèi)存單元釋放兩次,導(dǎo)致程序運(yùn)行出錯(cuò)。解答要點(diǎn):以下幾點(diǎn)必須說清楚:(公 (其它類成 員函數(shù)或全局函數(shù)可以通過該類的對(duì)象訪問該類的公有數(shù)據(jù)成員和調(diào)用該類的的公有成員 函數(shù)。不是在類中定義的成員函數(shù)都是全局函數(shù)。(全局函數(shù)或類的成員函數(shù)類中用friend簡(jiǎn)述結(jié)構(gòu)化的程序設(shè)計(jì)、面向?qū)ο蟮某绦蛟O(shè)計(jì)的基本思想。結(jié)構(gòu)structclass解答要點(diǎn):struct 和class 都可以定義類,但是缺省訪問權(quán)限說明時(shí),struct 的成員是公有的,而class 的成員是私有的。在C+中,struct 可被cl

7、ass 代替。三、找出下面程序(或程序段)中的語法錯(cuò)誤,并予以糾正(每小題4 分,共 8 分)#include void main()char str5 =First,Second,Third,Forth,Fifth;char *cp =str4,str3,str2,str1,str0; int i;while(i=5)printf(%c ,*(cp+i);i+; char str5 =First,Second,Third,Forth,Fifth;應(yīng)為char str510 =First,Second,Third,Forth,Fifth; while(i=5)應(yīng)為while(i5) print

8、f(%c ,*(cp+i);應(yīng)為printf(%s,*(cp+i); int i;應(yīng)為int i=0;#include void main()int max,a,i; scanf(%d%d,max,a); double xmax;for (i=0;imax;i+) xi=sqrt(a*i); 增加#include scanf(%d%d,max,a);應(yīng)為scanf(%d%d,&max,&a); double delete x;(8shape則是一個(gè)通用的用以求不同形狀的圖形面積總和的函數(shù)。請(qǐng)從shapeclass shape public:virtual float area( )=0;flo

9、at total(shape *s ,int n)float sum=0.0; for(int sum+=si-area( ); return sum;class Triangle:public Shapepublic:Triangle(double h,double double Area() constreturn H*W*0.5;private: double H,W;class Rectangle:public Shapepublic:Rectangle(double h,double w)H=h;W=w; double Area()constreturn H*W;private: double H,W;五、 分)完成順序查找函數(shù)f_seq(與表中元素比較。如果找到所需元素,則查找成功,并打印出它在表中的順序號(hào)#include void f_seq(char *list,char *object,int len)/list 指針數(shù)組,指向字符串/object 模式串/len 表的長(zhǎng)度char *p;int strcmp(char *s,char *t); p=list;while () if (strcmp(*p,object)=0)break;else; if (pnext=NULL p=head-

溫馨提示

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

評(píng)論

0/150

提交評(píng)論