11-12面向?qū)ο蟪绦蛟O(shè)計(jì)(二)試卷(B)Word版_第1頁(yè)
11-12面向?qū)ο蟪绦蛟O(shè)計(jì)(二)試卷(B)Word版_第2頁(yè)
11-12面向?qū)ο蟪绦蛟O(shè)計(jì)(二)試卷(B)Word版_第3頁(yè)
11-12面向?qū)ο蟪绦蛟O(shè)計(jì)(二)試卷(B)Word版_第4頁(yè)
11-12面向?qū)ο蟪绦蛟O(shè)計(jì)(二)試卷(B)Word版_第5頁(yè)
已閱讀5頁(yè),還剩2頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、華僑大學(xué) 面向?qū)ο蟪绦蛟O(shè)計(jì)(二) 試卷(B)系別 考試日期 2012年 06月27日姓名 學(xué)號(hào) 成績(jī) 一、填空題(15分,每空1分)1. 類的成員包括_和_。2. 建立一個(gè)類對(duì)象時(shí),系統(tǒng)自動(dòng)調(diào)用_。3. 如果希望類的成員為該類所有對(duì)象所共享,可以使用關(guān)鍵字_來(lái)修飾。4. 如果希望完成所謂的深拷貝,需要重載_構(gòu)造函數(shù)。5. 類成員的訪問控制包括_、_和_。6. 不屬于類成員但卻可以訪問類的私有數(shù)據(jù)變量的函數(shù)是該類的_。7. 運(yùn)算符和 7. 下列關(guān)于構(gòu)造函數(shù)的描述中,錯(cuò)誤的是_。A) 構(gòu)造函數(shù)可以沒有參數(shù) B) 構(gòu)造函數(shù)不可以設(shè)置默認(rèn)參數(shù)C) 構(gòu)造函數(shù)可以是內(nèi)聯(lián)函數(shù) D) 構(gòu)造函數(shù)可以重載8. 下

2、面描述中,表達(dá)錯(cuò)誤的是_。A) 公有繼承時(shí)基類中的public成員在派生類中仍是public的B) 公有繼承是基類中的private成員在派生類中仍是private的 C) 公有繼承是基類中的protected成員在派生類中仍是protected的D) 私有繼承時(shí)基類中的public成員在派生類中是private的9. 運(yùn)算符重載是對(duì)已有的運(yùn)算符賦予多重含義,因此_A) 可以對(duì)基本類型(如double類型)的數(shù)據(jù),重新定義“+”運(yùn)算符的含義B) 可以改變一個(gè)已有運(yùn)算符的優(yōu)先級(jí)和操作數(shù)個(gè)數(shù)C) C+中已經(jīng)有的所有運(yùn)算符都可以重載D) 只能重載C+中已有的運(yùn)算符,不能定義新運(yùn)算符10. 已知類My

3、Int的定義如下:class MyIntint data;public:MyInt(int d) data = d; ;下列對(duì)MyInt類對(duì)象數(shù)組的定義和初始化語(yǔ)句中,正確的是A) MyInt myInts3;B) MyInt myInts3 = MyInt(2);C) MyInt myInts3 = MyInt(3), MyInt(4), MyInt(5); D) MyInt* myInts = new MyInt3;三、閱讀以下程序并填空(填上正確的語(yǔ)法成分),使其成為完整的程序(20分,每空2分)(1). 已知向量MyVector的定義如下,data存放數(shù)據(jù),capacity是當(dāng)前分配的

4、空間大小,length是data里實(shí)際存放的元素?cái)?shù)目。(1)實(shí)現(xiàn)構(gòu)造函數(shù),分配大小為n的空間,并都初始化為0;(2)實(shí)現(xiàn)析構(gòu)函數(shù),釋放分配的空間;(3)重載流插入運(yùn)算符,將當(dāng)前data的所有元素都依次打印出來(lái),格式如3 2 4 5。class MyVectorint *data; /指向存放數(shù)組數(shù)據(jù)的空間int capacity; /當(dāng)前分配的空間大小int length;/當(dāng)前實(shí)際的元素?cái)?shù)目 public: MyVector(int n);MyVector() delete _(1)_; _(2)_ostream& operator0);data = _(3)_;capacity = n;l

5、ength = 0;for(int i = 0; in; i+)*(data+i) = 0;ostream& operator(ostream& out, const MyVector& mv)/重載運(yùn)算符for( int i =0; _(4)_; i+)out _(5)_ “ “;out endl;return out;(2). 類Derived公共繼承于Base。Base的構(gòu)造函數(shù)有一個(gè)參數(shù)i用于初始化其數(shù)據(jù)成員v。Derived的構(gòu)造函數(shù)有三個(gè)參數(shù)val1,val2和val3,分別用于初始化Base的數(shù)據(jù)成員v以及Derived的數(shù)據(jù)成員v1、v2。class Baseint v;pub

6、lic:Base(int i):_ (6)_;class Derived:_(7)_ int v1,v2;public:Derived(int val1, int val2, int val3):_(8)_, _(9)_,_ (10)_ ;四、讀程序,寫出運(yùn)行結(jié)果(25分,每題5分)1. void f(int i)static int calledTimes = 0;cout No. +calledTimes in f( i ) endl;int main()int i = 0;for( int i = 0; i 5; i+) f(i+1);cout i = i endl;2. class B

7、asepublic:void print()coutIn Base:print() endl;class Derived:public Basepublic:void print()Base:print();coutIn Derived:print() endl;int main()Derived d;d.print();return 0;3. class Base public:Base(int i=0,int j=0) a=i;b=j;void print( ) cout”a=”a”,b=”bendl;private :int a,b;void main( ) Base m, n(4,8)

8、;m.print( );n.print( );4. class MyClasspublic:MyClass() cout MyClass() endl;MyClass(const MyClass& another) cout MyClass(const MyClass& another() endl;MyClass& operator=(const MyClass& rhs) cout operator=() endl; return *this;int main()MyClass mc1;MyClass mc2 = mc1;MyClass mc3(mc2);mc1 = mc3;return

9、0;5. class Animalpublic:Animal() cout Animal:Animal() endl; Animal() cout Animal:Animal() endl; ;class Cat:public Animalpublic:Cat() cout Cat:Cat() endl;Cat() cout Cat:Cat() endl;int main()Cat animal;五、編程題(共20分)1. 請(qǐng)實(shí)現(xiàn)三個(gè)可以支持兩個(gè)、三個(gè)和n個(gè)整數(shù)相加的重載函數(shù)。函數(shù)名統(tǒng)一為add,返回值統(tǒng)一為int,例如兩個(gè)整數(shù)相加的版本為 int add(int, int)。2. 給定類In

10、tegerNumber的定義如下,要求實(shí)現(xiàn)如下五個(gè)運(yùn)算符重載。class IntegerNumberint value;public:IntegerNumber(int n = 0) value = n; IntegerNumber operator+(const IntegerNumber& rhs);IntegerNumber operator-(const IntegerNumber& rhs);friend IntegerNumber operator+(IntegerNumber& a, int x);/后+friend IntegerNumber& operator+(IntegerNumber& a);/前+friend ostream& operator(ostream& out, IntegerNumber& rhs);華僑大學(xué) 面向?qū)ο蟪绦蛟O(shè)計(jì)(二) 試卷(B)答題紙系別 考試日期 2012年 06月27日姓名 學(xué)號(hào) 成績(jī) 題號(hào)第一題第二題第三題第四題第五題總分成績(jī)閱卷人一、填空題 (15分,每空1分)1. 、 2. 3. 4. 5. 、 、 6. 7. 8. 9. 、 、 10. 二、選擇題 (20分,每小題2分) 1. 2. 3. 4. 5. 6. 7. 8

溫馨提示

  • 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ù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 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)論