面向?qū)ο驛卷(含答案)_第1頁
面向?qū)ο驛卷(含答案)_第2頁
面向?qū)ο驛卷(含答案)_第3頁
面向?qū)ο驛卷(含答案)_第4頁
面向?qū)ο驛卷(含答案)_第5頁
已閱讀5頁,還剩9頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、課程面向?qū)ο蟪绦蛟O(shè)計考試形式(開/閉卷,考試/查)一、填空題:(10分,每個空格1分)1.C+語言面向?qū)ο蟪绦蛟O(shè)計的三個基本特性是 數(shù)據(jù)封裝 、 繼承 、 多態(tài)性 。2.類的數(shù)據(jù)隱藏是通過定義成員為 私有(或private) 或 受保護(或protected) 來實現(xiàn)。3.創(chuàng)建一個派生類的對象時,如果基類帶有構(gòu)造函數(shù)則先調(diào)用 基 類的構(gòu)造函數(shù),然后調(diào)用 派生類 類的構(gòu)造函數(shù)。4.如果在派生類中定義了一個成員函數(shù),其函數(shù)原型與從父類繼承下來的成員函數(shù)的函數(shù)原型完全相同的,那么該函數(shù)的實現(xiàn)稱為是對 父類 同名函數(shù)的 重定義 。5.在C+語言中,根據(jù)除號“/”左右操作數(shù)的類型自動確定其是整除或是一般

2、除法,這種機制稱為 運算符重載 。二是非題(回答“Y”或“N”, 10分,每小題1分)1.類的protected成員是不能被繼承的。N2.構(gòu)造函數(shù)的名字不必與類的名字相同。N3.一個類的友員函數(shù)可以使用該類的私有成員。Y4.符號不能重載。N5.析造函數(shù)原型沒有返回類型。Y6.類TEST的函數(shù)成員TEST(const TEST & obj)稱為拷貝構(gòu)造函數(shù)。Y7.類B繼承了類A,二個類都有public成員void show(),則派生類的void show()覆蓋了基類的void show()。Y8.函數(shù)重載是動態(tài)綁定。N 9.類模板不能直接生成對象。Y10.類屬函數(shù)的實例化是隱式。Y三選擇題

3、(20分,每空2分)1.設(shè)有一顯示2個整數(shù)相加或2個實數(shù)相加或2個字符串相加(連)的函數(shù),請運用函數(shù)重載方法設(shè)計此函數(shù)add( ),并設(shè)計一個主函數(shù)調(diào)用它。int sdd( (1) B )return x+y;double add( (2) A )return x+y;char * add( (3) D )char *str;str=new char(strlen(x)+strlen(y)+1);strcpy(str,x);strcat(str,y);return str;int main(int argc, char* argv)coutadd(10,20)endl;coutadd(10.1

4、0,20.20)endl;coutadd(abc,fghi)endl;return 0;(1)A、int x , double yB、int x , int yC、double x , int yD、char * x , int y(2)A、double x , double yB、int x , int yC、int x , double yD、float x , int y(3)A、char x , double yB、int x , float yC、double x , double yD、char * x , char * y2. 創(chuàng)建一個學生類,數(shù)據(jù)成員包括:學號、姓名、成績;成員

5、函數(shù)包括:構(gòu)造函數(shù)、輸入數(shù)據(jù)函數(shù)、顯示函數(shù)和取成績。主函數(shù)默認1位同學數(shù)據(jù),輸入1位同學數(shù)據(jù),顯示這2位同學的數(shù)據(jù)。class STUDENTprivate: int num;char name20;float score; (4) C :STUDENT()num=0;strcpy(name,”);score=0;STUDENT( (5) B x , char * (6) C , (7) D )num=x;strcpy(name,y);score=z;void input() coutnumnamescore; void print() coutn學號、姓名、成績: (8) C ; (9) C

6、 get_score() return score; ;void main()STUDENT stu1(1001,”李明”,90),stu2;stu2. (10) D ;stu1.print();stu2.print();(4)A、privateB、protectedC、publicD、struct(5)A、charB、intC、floatD、double(6)A、iB、xC、yD、z(7)A、int iB、double yC、char *zD、float zA、name 、num 、 score ;B、name 、 score 、 num ;C、num 、 name 、 score ; D、

7、num 、 score 、name ;(9)A、charB、intC、floatD、double(10)A、name=“張三”B、num=1002C、score=98D、input()四閱讀程序,寫出下列程序的運行結(jié)果 (40分,每小題4分)1. 指出程序中的錯誤class Inventorychar name20;int quantity;float price;void init(char n,int p,int q);void printInv();void main()Inventory p1,p2,p3;p1.quantity=28;2. 指出程序中的錯誤class COMPLEX

8、public : COMPLEX(double r=0, double i=0) ; COMPLEX operator-(const COMPLEX & other) ; COMPLEX operator=(const COMPLEX & other) ;private : double real, image ;void main()float x ; COMPLEX y (10,20), z (2,3), sum ; sum= x-y ; sum=sum-z ; sum- ;3. 寫出下列程序的運行結(jié)果class A public:int n; ; class B:public A; cl

9、ass C:public A; class D:public B,public C int getn()return B:n; ; void main() D d; d.B:n=10; d.C:n=20; coutd.B:n,d.C:nendl; 10,204. 寫出下列程序的運行結(jié)果class BASEprivate:char c; public: BASE(char n):c(n) virtualBASE()coutc; ; class DERIVED:public BASEprivate:char c; public: DERIVED(char n):BASE(n+1),c(n) DER

10、IVED()coutc; ; int main() DERIVED obj(X); return 0; XY5. 寫出下列程序的運行結(jié)果class pointprivate:int x1,x2;public:point(int x,int y) x1=x; x2=y; int x_cord() return x1; int y_cord() return x2; ;void main()point data(5,6);coutdata.x_cord() data.y_cord()endl;5 66. 寫出下列程序的運行結(jié)果class Apublic : A(int n) i=n ; cout“

11、初始化i的值為:”get_i()n; A() cout“釋放A的對象?!眓 ; int get_i () return i ; private : int i ; ;class B : public A public : B(int n, int m) : A(n)j=m ; cout“初始化j的值為:”get_j()n ; B()cout“釋放B的對象?!眓 ; int get_j () return j ; private : int j ; ;void main()B obj (1,2) ; cout“創(chuàng)建了一個B的對象。值為:”obj.get_i()“ ”obj.get_j()n ;初

12、始化i的值為:1初始化j的值為:2創(chuàng)建了一個B的對象。值為:1 2釋放B的對象。釋放A的對象。7、寫出下列程序的運行結(jié)果class Test;void fun1(Test t);Test fun2();class Testpublic:Test(int n=1) val=n; coutCon.endl;Test(const Test& t) val=t.val; coutCopy con.endl;Test& operator = (Test& t) val=t.val; coutAssignment.endl;return *this;private:int val;void main()T

13、est t1(1);Test t2=t1;Test t3;t3=t1;fun1(t2);t3=fun2();void fun1(Test t)Test fun2()Test t;return t;Con.Copy con.Con.Assignment.Copy con.Con.Copy con.Assignment.8、寫出下列程序的運行結(jié)果class Apublic:A()coutAs con.endl;A()coutAs des.endl;class Bpublic:B()coutBs con.endl;B()coutBs des.endl;class C:public A,public

14、Bpublic:C():member(),B(),A()coutCs con.endl;C()coutCs des.endl;private:A member;void main()C obj; As con.Bs con.As con.Cs con.Cs des.As des.Bs des.As des.9、寫出下列程序的運行結(jié)果class Rpublic:R(int r1,int r2) R1=r1;R2=r2;void print();void print() const;private:int R1,R2;void R:print()coutR1:R2endl;void R:print

15、() constcoutR1;R2endl;void main()R a(5,4);a.print();const R b(20,52);b.print(); 5:420;5210、寫出下列程序的運行結(jié)果class A public:virtual void act1();void act2() act1();void A:act1()coutA:act1() called. endl;class B : public Apublic:void act1();void B:act1()coutB:act1() called. endl;void main()B b; b.act2();B:ac

16、t1() called.五編程題 ( 20分,每題10分)1、編寫一程序,定義一個合子類BOX,它能提供計算合子的體積和表面積。class BOXpublic:BOX()length=0;width=0;height=0;BOX(double l,double w,double h)length=l;width=w;height=h;void GetValue(double l,double w,double h)length=l;width=w;height=h;double bulk()return ( length * width * height);double sufasearea(

17、)return ( 2*(length * width + length * height + width * height);private:double length,width,height;void main()BOX a(10,20,30);couta盒子的體積:a.bulk()endl;couta盒子的表面積:a.sufasearea()endl;2、設(shè)計一個點類Point(只需數(shù)據(jù)成員和成員函數(shù)原型,不需寫函數(shù)定義),實現(xiàn)點對象之間的各種運算。 class Point private:int x,y; public:Point(); Point(int i,int j); Poi

18、nt(Point &); Point();void offset(int,int); / 提供對點的偏移 void offset(Point); / 重載,偏移量用Point類對象表示 bool operator=(Point); / 運算符重載,判斷兩個對象是否相同 bool operator!=(Point); / 運算符重載,判斷兩個對象是否不相同 void operator+=(Point); /運算符重載,將兩個點對象相加 void operator-=(Point); / 運算符重載,將兩個點對象相減 Point operator+(Point ); / 運 算符重 載,相加并將結(jié)果放在左操作數(shù)中 Point operator-(Point); / 運算符重載,相減并將結(jié)果放在左操作數(shù)中

溫馨提示

  • 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)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論