C++面向?qū)ο蟪绦蛟O(shè)計(jì)期末考試試題_第1頁(yè)
C++面向?qū)ο蟪绦蛟O(shè)計(jì)期末考試試題_第2頁(yè)
C++面向?qū)ο蟪绦蛟O(shè)計(jì)期末考試試題_第3頁(yè)
C++面向?qū)ο蟪绦蛟O(shè)計(jì)期末考試試題_第4頁(yè)
C++面向?qū)ο蟪绦蛟O(shè)計(jì)期末考試試題_第5頁(yè)
免費(fèi)預(yù)覽已結(jié)束,剩余2頁(yè)可下載查看

下載本文檔

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

文檔簡(jiǎn)介

1、I.說(shuō)明對(duì)象或變量初始化后不會(huì)被修改。c. 中間一個(gè)3.非靜態(tài) d.公共次數(shù)更多d.提供。b.調(diào)用程序 c.上述二者參數(shù)就作為這一參數(shù)。 d.以上都不是 類成員。O以上都不是d.以上都不是到 float d.從 float 至U inta.杭州電子科技大學(xué)學(xué)生考試卷(A)卷考試課 程面向?qū)ο蟪绦蛟O(shè)計(jì)考試日 期06年6月日成績(jī)課程號(hào)B1002100教師號(hào)任課教師姓名樓永堅(jiān)考生姓 名學(xué)號(hào)(8位)年級(jí)05專業(yè)050511/2/3座位 號(hào)、判斷題(15分)(對(duì)的打,錯(cuò)的打X)1. 友元函數(shù)用于允許一個(gè)函數(shù)訪問(wèn)不相關(guān)類的私有部分。2. 構(gòu)造函數(shù)可以被繼承。3. 動(dòng)態(tài)綁定的多態(tài)性是通過(guò)虛函數(shù)實(shí)現(xiàn)的。4.

2、在C+中,傳引用調(diào)用等同于傳地址調(diào)用。5. 重載函數(shù)必須有不同的參數(shù)列表。6. 可以用delete釋放不是用new運(yùn)算符分配的內(nèi)存。7. 類成員的默認(rèn)訪問(wèn)模式是private。8. 在類Time中的析構(gòu)函數(shù)可以聲明為:void Time(int);9. const對(duì)象必須初始化。10. 在C+中,只能重載已有的運(yùn)算符。I) 2) X 3) V 4) X 5) V 6) X 7) V 8) X 9) V10) V二、選擇題(20分)I) c 2) b 3) c 4) b 5) c 6) a 7) c 8) a 9) c 10) b11.、選擇題(20分)關(guān)鍵字a. static b. publi

3、c c. const d. in li nel.如果調(diào)用帶有默認(rèn)參數(shù)的函數(shù)時(shí)缺少一個(gè)參數(shù),則a.第一個(gè) b.最后一個(gè)成員函數(shù)可聲明為靜態(tài)的,條件是它不訪問(wèn)a.靜態(tài)b.常數(shù)c.內(nèi)聯(lián)函數(shù)執(zhí)行起來(lái)比標(biāo)準(zhǔn)函數(shù)a.更慢b.更快c.默認(rèn)參數(shù)的值由a.該函數(shù)5.在C+中,混合類型表達(dá)式 。允許存在b.為一錯(cuò)誤c. 從int7. 表達(dá)式 Iong(intVar) 也可表示為 。var = long; Var(long)c. (long)intVard.以上都不是8. 靜態(tài)數(shù)據(jù)成員的生存期 。a.與整個(gè)程序相同b.不長(zhǎng)于類的生存期c.取決于創(chuàng)建的對(duì)象數(shù)d.以上都不是9. 要讓一個(gè)類中的所有對(duì)

4、象具有共同的數(shù)據(jù),請(qǐng)使用 。a.常數(shù)成員變量b.私有數(shù)據(jù)成員|c.靜態(tài)數(shù)據(jù)成員d.以上都是10. 設(shè)置虛基類的目的是:a.簡(jiǎn)化程序b.消除二義性c.提高運(yùn)行效率d.減少目標(biāo)代碼三、指出下列程序片段中的錯(cuò)誤標(biāo)號(hào),寫出正確語(yǔ)句或解釋錯(cuò)在何處。(20分) int index=675;1)*ptr=555; ptr是指向整數(shù)常量的指針ntptr=&another;ntptr是常量指針,不能指向別的的變量2) int arrp;應(yīng)改為:int *arrp; delete arrp; 應(yīng)改為: delete arrp;3) return basedata;/ 在 border_and_menu 中弓丨用

5、basedata 時(shí)產(chǎn)生二義性,應(yīng)使用虛 基類_應(yīng)改為:class border:virtual public window ;class menu: virtual public win dow ;1) const int *ptr =&in dex; int *const n tptr =&in dex; *ptr=555; 勺 tptr=666; int ano ther=8; ptr=&ano ther; n tptr=&ano ther;2) int arrp; arrp=new in t15; delete arrp;3) 下面程序?yàn)槭裁磿?huì)編譯錯(cuò)誤,并改正錯(cuò)誤(提出解決辦法)。I.

6、5.class win dowfriend double count(A&);public:protected:A(double t, double r):total(t),rate(r)int basedata;private:Jdouble total;class border: public windowdouble rate; J;class menu: public wi ndow;double count(A& a) class border_a nd_me nu: public border, public menua.total+=a.rate*a.total;return a

7、.total;public:int show()int main( void) retur n basedata;A x(80,0.5),y(100,0.2);coutco un t(x),co un t(y)n: coutco un t(x)n:return 0;4)改正下面程序段中的錯(cuò)誤,寫出整個(gè)正確的程序段template執(zhí)行結(jié)果:void print(T *a) coutvavvn;2)void mai n()#in cludeusing n amespace std;const int x=0;class Countcoutvvyvv n private:int y;static i

8、n t coun ter;x=5;in t obj_id;int* ppublic:p=&y;Coun t(); /con structorprin t(p);static void display_total(); /static functionreturn 0;void display();Co un t(); /destructor四、寫出下面程序的執(zhí)行結(jié)果:(15分);int Count:counter; /definition of static data member1) #include Coun t:Co un t() /c on structorusing n amespa

9、ce std;class Acoun ter+;obj_id = coun ter;DERIVED()coutc;Coun t:Co un t() /destructor;int main(void) DERIVED(X);coun ter-;return 0;coutObject nu mber obj_id being destroyedn;void Coun t:display_total() /static fun cti on五、程序填空:(10分)#in clude cout Number of objects created is = co un tere ndl;using n

10、 amespace std;class Avoid Coun t:display()(1)cout Object ID is obj_ide ndl;char n ame80;public:nt main( void)A(2)(3);Cou nt a1;class B(4)Coun t:display_total();Count a2, a3,a4;public:Coun t:display_total();B(const char*n)(5)a2.display();void PrintName( ) cout ”ame:”nameendl;a4.display();return 0;voi

11、d mai n()B b1( Ling Li ”;3) #include using n amespace std;bl.Pri ntName();class BASE /執(zhí)行結(jié)果:name: Ling Li六、編程題(20分)char c;1 .編與程序:疋義抽象基類Shape,由它派生出五個(gè)派生類:Circle (圓形)、Square (正方形)、public:Rectangle (長(zhǎng)方形)、Trapezoid (梯形)和Triangle (三角形),用虛函數(shù)分別計(jì)算各種圖形的面積,BASE(char n):c( n)并求出它們的和。要求用基類指針數(shù)組。使它的每一個(gè)兀素指向一個(gè)派生類的對(duì)象

12、。virtual BASE()coutc;注:主函數(shù)中定義如下對(duì)象Circle circle(12.6);class DERIVED:public BASESquare square(3.5);char c;Rectangle rectangle(4.5,8.4);public:Trapezoid trapezoid(2.0,4.5,3.2);DERIVED(char n):BASE( n+1),c( n)Trian gle tria ngle(4.5,8.4);杭州電子科技大學(xué)學(xué)生考試卷(A)答案考試課 程面向?qū)ο蟪绦蛟O(shè)計(jì)考試日 期06年6月日成績(jī)課程號(hào)B1002100教師號(hào)任課教師姓名樓永

13、堅(jiān)考生姓 名學(xué)號(hào)(8位)年級(jí)05專業(yè)050511/2/3座位 號(hào)一、判斷題(15分)I) V 2) X 3) V4)X 5) V6)X 7) V8)X9)V10)V二、選擇題(20分)I) c 2) b3)c 4) b5)c6)a 7) c8)a9)c 10) b三、 指出下列程序片段中的錯(cuò)誤,并解釋錯(cuò)在何處。(20分)1) *ptr=555; ptr是指向整數(shù)常量的指針ntptr=&another;ntptr是常量指針,不能指向別的的變量2) int arrp; 應(yīng)改為:int *arrp; delete arrp; 應(yīng)改為: delete arrp;3) return basedata;/

14、 在 border_and_menu 中弓丨用 basedata 時(shí)產(chǎn)生二義性,應(yīng)使用虛基類 應(yīng)改為:class border:virtual public window ;class menu: virtual public win dow ;4)整個(gè)正確的程序段(參考):#in clude 加本句template / 力口 type name void print(T *a)coutan;void mai n() int y=10;/y應(yīng)先聲明后使用,并給初值const int x=0;coutyn:x=5;x為con st,去掉該句int* p;p=&y;prin t(p);/ retu

15、rn 0; main返回為void,去掉該句 四、寫出下面程序的執(zhí)行結(jié)果:(15分)1)2)unbei* of objects created is s 1unhei of objects created is - 4bject ID is 2hject ID is 4bject number 4bject number 3bject number 2bject number 1being destroyed bedesbein destrov&d being dlestroved3) XY五、程序填空:(10分)(1) protected:或 public (2) const char *n

16、(3) strcpy(name,n);(4) : public A 或:protected A ( 5) :A(n)六、編程題(20分)I.#in elude using n amespace std;class Shapepublic:virtual double area() const =0;class Circle:public Shapepublic:Circle(double r):radius(r)virtual double area() const return 3.14159*radius*radius; protected:double radius;class Squa

17、re:public Shapepublic:Square(double s):side(s)virtual double area() const retur n side*side; protected:double side;class Recta ngle:public Shapepublic:Recta ngle(double w,double h):width(w),height(h) virtual double area() const retur n width*height; protected:double width,height;class Trapezoid:publ

18、ic Shapepublic:Trapezoid(double t,double b,double h):top(t),bottom(t),height(h) virtual double area() const return 0.5*(top+bottom)*height; protected:double top,bottom,height;class Trian gle:public Shapepublic:Trian gle(double w,double h):width(w),height(h)virtual double area() const retur n 0.5*width*height; protected:double width,height;i

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(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)論