下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、杭州電子科技大學(xué)學(xué)生考試卷(A)卷考試課程面向?qū)ο蟪绦蛟O(shè)計(jì)考試日期06年6月 日成績課 程 號B1002100教 師 號任課教師姓名樓永堅(jiān)考生姓名學(xué)號(8位)年級05專業(yè)050511/2/3座位號一、 判斷題(15分)(對的打,錯的打)1. 友元函數(shù)用于允許一個(gè)函數(shù)訪問不相關(guān)類的私有部分。2. 構(gòu)造函數(shù)可以被繼承。3. 動態(tài)綁定的多態(tài)性是通過虛函數(shù)實(shí)現(xiàn)的。4. 在c+中,傳引用調(diào)用等同于傳地址調(diào)用。5. 重載函數(shù)必須有不同的參數(shù)列表。6. 可以用delete釋放不是用new運(yùn)算符分配的內(nèi)存。7. 類成員的默認(rèn)訪問模式是private。8. 在類Time中的析構(gòu)函數(shù)可以聲明為:void Time
2、(int);9. const對象必須初始化。10. 在c+中,只能重載已有的運(yùn)算符。1) 2) 3) 4) 5) 6) 7) 8) 9) 10)二、選擇題(20分)1) c 2)b 3) c 4)b 5)c 6) a 7)c 8)a 9)c 10)b11.二 、選擇題(20分)1. 關(guān)鍵字 _ 說明對象或變量初始化后不會被修改。 a. static b. public c. const d. inline2. 如果調(diào)用帶有默認(rèn)參數(shù)的函數(shù)時(shí)缺少一個(gè)參數(shù),則_參數(shù)就作為這一參數(shù)。 a. 第一個(gè) b. 最后一個(gè) c. 中間一個(gè) d. 以上都不是3. 成員函數(shù)可聲明為靜態(tài)的,條件是它不訪問 _類成員。
3、 a. 靜態(tài) b. 常數(shù) c. 非靜態(tài) d. 公共4. 內(nèi)聯(lián)函數(shù)執(zhí)行起來比標(biāo)準(zhǔn)函數(shù)_。a. 更慢 b. 更快 c. 次數(shù)更多 d. 以上都不是5. 默認(rèn)參數(shù)的值由_提供。 a. 該函數(shù) b. 調(diào)用程序 c. 上述二者 d. 以上都不是6. 在 C+ 中,混合類型表達(dá)式_。a. 允許存在 b. 為一錯誤 c. 從 int 到 float d. 從 float 到 int7. 表達(dá)式 long(intVar) 也可表示為 _。a. intvar = long; b. intVar(long) c. (long)intVar d. 以上都不是8. 靜態(tài)數(shù)據(jù)成員的生存期_。a. 與整個(gè)程序相同 b.
4、不長于類的生存期 c. 取決于創(chuàng)建的對象數(shù) d. 以上都不是9. 要讓一個(gè)類中的所有對象具有共同的數(shù)據(jù),請使用_。a. 常數(shù)成員變量 b. 私有數(shù)據(jù)成員 c. 靜態(tài)數(shù)據(jù)成員 d. 以上都是10. 設(shè)置虛基類的目的是:a.簡化程序 b.消除二義性 c.提高運(yùn)行效率 d.減少目標(biāo)代碼三 、指出下列程序片段中的錯誤標(biāo)號,寫出正確語句或解釋錯在何處。(20分)int index=675; 1)*ptr=555; ptr是指向整數(shù)常量的指針ntptr=&another; ntptr是常量指針,不能指向別的的變量2)int arrp; 應(yīng)改為:int *arrp;delete arrp; 應(yīng)改為:dele
5、te arrp;3)return basedata;/ 在border_and_menu中引用basedata時(shí)產(chǎn)生二義性,應(yīng)使用虛基類應(yīng)改為:class border:virtual public window ;class menu: virtual public window ;1)const int *ptr=&index;int *const ntptr=&index;*ptr=555;*ntptr=666;int another=8;ptr=&another;ntptr=&another;2) int arrp;arrp=new int15;delete arrp;3)下面程序?yàn)槭?/p>
6、么會編譯錯誤,并改正錯誤(提出解決辦法)。 class window protected: int basedata;class border: public window ;class menu: public window ;class border_and_menu: public border, public menu public: int show() return basedata; 4)改正下面程序段中的錯誤,寫出整個(gè)正確的程序段templatevoid print(T *a)coutan;void main( )const int x=0;coutyn;int y;x=5;i
7、nt* pp=&y;print(p);return 0;四 、寫出下面程序的執(zhí)行結(jié)果:(15分)1)#include using namespace std;class Afriend double count(A&);public:A(double t, double r):total(t),rate(r)private:double total;double rate;double count(A& a)a.total+=a.rate*a.total;return a.total;int main(void)A x(80,0.5),y(100,0.2);coutcount(x),count
8、(y)n;coutcount(x)n;return 0;執(zhí)行結(jié)果:2)#include using namespace std;class Count private: static int counter; int obj_id; public: Count(); /constructor static void display_total(); /static function void display(); Count(); /destructor ; int Count:counter; /definition of static data member Count:Count() /
9、constructor counter+; obj_id = counter; Count:Count() /destructor counter-; coutObject number obj_id being destroyedn; void Count:display_total() /static function cout Number of objects created is = counterendl; void Count:display() cout Object ID is obj_idendl; int main(void) Count a1; Count:displa
10、y_total(); Count a2, a3,a4; Count:display_total(); a2.display(); a4.display(); return 0;3)#include using namespace std;class BASE char c; public: BASE(char n):c(n) virtual BASE()coutc; ; class DERIVED:public BASE char c; public: DERIVED(char n):BASE(n+1),c(n) DERIVED()coutc; ; int main(void) DERIVED
11、(X); return 0; 五、 程序填空:(10分)#include using namespace std;class A_(1)_char name80;public:A( _(2)_ ) _(3)_ ;class B_(4)_public:B(const char*n)_(5)_void PrintName( ) cout”name:”nameendl;void main( )B b1(“Ling Li”);b1.PrintName( ) ; /執(zhí)行結(jié)果:name: Ling Li六、編程題(20分)1編寫程序:定義抽象基類Shape,由它派生出五個(gè)派生類:Circle(圓形)、Sq
12、uare(正方形)、 Rectangle( 長方形)、Trapezoid (梯形)和Triangle (三角形),用虛函數(shù)分別計(jì)算各種圖形的面積,并求出它們的和。要求用基類指針數(shù)組。使它的每一個(gè)元素指向一個(gè)派生類的對象。 注:主函數(shù)中定義如下對象Circle circle(12.6); Square square(3.5); Rectangle rectangle(4.5,8.4); Trapezoid trapezoid(2.0,4.5,3.2); Triangle triangle(4.5,8.4); 杭州電子科技大學(xué)學(xué)生考試卷(A)答案考試課程面向?qū)ο蟪绦蛟O(shè)計(jì)考試日期06年6月 日成績課
13、 程 號B1002100教 師 號任課教師姓名樓永堅(jiān)考生姓名學(xué)號(8位)年級05專業(yè)050511/2/3座位號一、判斷題(15分)1) 2) 3) 4) 5) 6) 7) 8) 9) 10)二、選擇題(20分)1) c 2)b 3) c 4)b 5)c 6) a 7)c 8)a 9)c 10)b三 、指出下列程序片段中的錯誤,并解釋錯在何處。(20分)1)*ptr=555; ptr是指向整數(shù)常量的指針ntptr=&another; ntptr是常量指針,不能指向別的的變量2)int arrp; 應(yīng)改為:int *arrp;delete arrp; 應(yīng)改為:delete arrp;3)retur
14、n basedata;/ 在border_and_menu中引用basedata時(shí)產(chǎn)生二義性,應(yīng)使用虛基類應(yīng)改為:class border:virtual public window ;class menu: virtual public window ;4)整個(gè)正確的程序段(參考):#include /加本句template /加typenamevoid print(T *a)coutan;void main( ) int y=10; /y應(yīng)先聲明后使用,并給初值const int x=0;coutyn;/x=5; x為const,去掉該句int* p; p=&y;print(p);/ret
15、urn 0; main返回為void ,去掉該句四 、寫出下面程序的執(zhí)行結(jié)果:(15分)1)2)3)XY五、程序填空:(10分)(1)protected:或public (2)const char *n (3)strcpy(name,n);(4):public A或:protected A (5):A(n)六、編程題(20分)1#include using namespace std;class Shapepublic: virtual double area() const =0; ;class Circle:public Shapepublic:Circle(double r):radiu
16、s(r) virtual double area() const return 3.14159*radius*radius; protected: double radius; ;class Square:public Shapepublic: Square(double s):side(s) virtual double area() const return side*side; protected: double side;class Rectangle:public Shapepublic: Rectangle(double w,double h):width(w),height(h)
17、 virtual double area() const return width*height; protected: double width,height; ;class Trapezoid:public 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 Triangle:public Shapepublic: Triangle(double w,double h):width(w),height(h) virtual double area() const return 0.5*width*height; protected: double width,height; ;int main() Circle circle(1
溫馨提示
- 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030全球反流檢測設(shè)備行業(yè)調(diào)研及趨勢分析報(bào)告
- 2025年全球及中國搖擺式生物工藝容器行業(yè)頭部企業(yè)市場占有率及排名調(diào)研報(bào)告
- 2025商場地產(chǎn)蛇年新春暴富游園畫蛇添財(cái)主題活動策劃方案-
- 二手房買賣合同模板上淘寶
- 二手汽車轉(zhuǎn)讓三方協(xié)議合同書
- 產(chǎn)品購銷合同書范本
- 2025中餐館租賃合同
- 2025有關(guān)續(xù)簽勞動合同程序介紹
- 股權(quán)質(zhì)押借款合同樣本
- 拆除工程承包合同模板
- 搞笑小品劇本《大城小事》臺詞完整版
- 物業(yè)服務(wù)和后勤運(yùn)輸保障服務(wù)總體服務(wù)方案
- 人大代表小組活動計(jì)劃人大代表活動方案
- 《大模型原理與技術(shù)》全套教學(xué)課件
- 2023年護(hù)理人員分層培訓(xùn)、考核計(jì)劃表
- 《銷售培訓(xùn)實(shí)例》課件
- 2025年四川省新高考八省適應(yīng)性聯(lián)考模擬演練(二)地理試卷(含答案詳解)
- 【經(jīng)典文獻(xiàn)】《矛盾論》全文
- 鐵嶺衛(wèi)生職業(yè)學(xué)院單招參考試題庫(含答案)
- 出口潛力分析報(bào)告
- 大美陜西歡迎你-最全面的陜西省簡介課件
評論
0/150
提交評論