四川大學C++面向?qū)ο蟪绦蛟O計模擬試題10002_第1頁
四川大學C++面向?qū)ο蟪绦蛟O計模擬試題10002_第2頁
四川大學C++面向?qū)ο蟪绦蛟O計模擬試題10002_第3頁
四川大學C++面向?qū)ο蟪绦蛟O計模擬試題10002_第4頁
四川大學C++面向?qū)ο蟪绦蛟O計模擬試題10002_第5頁
已閱讀5頁,還剩13頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、C+面向?qū)ο蟪绦蛟O計模擬試題一一、單項選擇題(本大題共 10小題,每小題2分,共20分)在每小題列出的四個備選項中,只有一個是符合題目要求的,請將其代碼填寫在題后的括號內(nèi)。錯選、多選或未選均無分。1 .說明虛函數(shù)的關鍵字是(B)。A) inlineB) virtualC) defineD) static2 .在標準C+用,每個程序中都必須包含有這樣一個函數(shù),該函數(shù)的函數(shù)名為(A)。AmainB)MAINC)nameD)function3 . cout是某個類的標準對象的引用,該類是(A)。AostreamB)istreamC)stdoutD)stdin4 .如果在類外的非類的成員函數(shù)中有函數(shù)調(diào)

2、用CPoint:func();則函數(shù)func()是類CPoint的(C)。A)私有靜態(tài)成員函數(shù)B)公有非靜態(tài)成員函數(shù)C)公有靜態(tài)成員函數(shù)B)友元函數(shù)public、private 或 protected ,D) static5 .如果class類中的所有成員在定義時都沒有使用關鍵字 則所有成員缺省定義為(C)。A publicB) protectedC) private6. 一個類的所有對象共享的是(D)。A私有數(shù)據(jù)成員C)保護數(shù)據(jù)成員7 .動態(tài)聯(lián)編所支持的多態(tài)性稱為A虛函數(shù)C)編譯時多態(tài)性8 .定義類模板時要使用關鍵字(A constB)B)公有數(shù)據(jù)成員D)靜態(tài)數(shù)據(jù)成員(D)。B)繼承D)運行

3、時多態(tài)性D)。newC) deleteD) template9 .對虛基類的定義(A)。A)不需要使用虛函數(shù)C)必須使用private10 .類類型轉(zhuǎn)換函數(shù)(A)。A不能帶有參數(shù)C)只能帶2個參數(shù)B)必須使用虛函數(shù)D)必須使用publicB)只能帶一個參數(shù)D)只能帶3個參數(shù)二、填空題(本大題共 5小題,每小題2分,共10分)不寫解答過程,將正確的答案寫在每小題的空格內(nèi)。錯填或不填均無分。1 .在用C+進行程序設計時,最好用(new)代替malloc。2 .函數(shù)模板中緊隨template之后尖括號內(nèi)的類型參數(shù)都要寇以保留字(class或typename)。3 .編譯時多態(tài)性可以用(重載)函數(shù)實現(xiàn)

4、。4 .拷貝構(gòu)造函數(shù)用它所在類的(對象)作為參數(shù)。5 .用關鍵字static 修飾的類的成員稱為(靜態(tài))成員。三、程序分析題(本大題共 6小題,每小題5分,共30分)給出下面各程序的輸出結(jié)果。6 .閱讀下面程序,寫出輸出結(jié)果。#include <iostream>using namespace std;class Arraypublic:Array(int a, int iSize):elem(a), size(iSize)return size;)int &operator(int i)(return elemi - 1;)private:int *elem;int si

5、ze;);int main()(int s=3, 7, 2, 1,5;Array ar(s, 5);ar1 = 9;for (int i = 1; i <= 5; i+)cout << ari << ""cout << endl;return 0;上面程序的輸出結(jié)果為:9 7 2 1 57 .閱讀下面程序,寫出輸出結(jié)果。#include <iostream>using namespace std;template <class Type>void Print(Type a, int n)for (int i

6、= 0; i < n; i+)cout << ai << " "int main()int a = 5, 6, 8;double b = , ;Print(a, sizeof(a) / sizeof(int);Print(b, 2);cout << endl;return 0;上面程序的輸出結(jié)果為:5 6 88 .閱讀下面程序,寫出輸出結(jié)果。#include <iostream> using namespace std;class Test(public:Test(int n):num(n)(count+;Test()(

7、 void Print() const;static int GetCount() (return count;private:int num;static int count;void Test:Print() const (cout << this->num << " " << this->count << "")int main()(Test oTest1(6);();Test oTest2(8);();cout << Test:GetCount();cout <<

8、 endl;return 0;)上面程序的輸出結(jié)果為:618 2 29 .閱讀下面程序,寫出輸出結(jié)果。#include <iostream>using namespace std;class Test(public:Test(int a = 0, int b = 0, int c = 0):x(a), y(b), z(c) void Print()(cout << x << endl;cout << y << endl;)void Print() const(cout << z << endl;)private

9、:int x, y;const int z;);int main()(Test obj1;();Test obj2(1,6, 8);();const Test obj3(6, 0, 18);();return 0;上面程序的輸出結(jié)果為:0 0 1 6 1810 閱讀下面程序,寫出輸出結(jié)果。#include <iostream>using namespace std;class MyClassprivate:static int n;public:MyClass() n += 1; MyClass() n -= 1; static int GetNum() return n; ;in

10、t MyClass:n = 0;int main()cout << MyClass:GetNum() << endl;MyClass obj;cout << MyClass:GetNum() << endl;MyClass *p = new MyClass;delete p;cout << MyClass:GetNum() << endl;cout << "end" << endl;return 0;上面程序的輸出結(jié)果為:0 1 2 1 end11 閱讀下面程序,寫出輸出結(jié)果。#

11、include <iostream>using namespace std;class Aprivate:int a;public:A() cout << "無參構(gòu)造函數(shù)"<< endl; A(int a) cout << " 含參構(gòu)造函數(shù) a=" << a << endl; A(const A &copy): a cout << " 復制構(gòu)造函數(shù)"<< endl; A() cout << " 析構(gòu)函數(shù)&quo

12、t;<< endl; ;int main()A objl, obj2(1), obj3(obj2);return 0;上面程序的輸出結(jié)果為:無參構(gòu)造函數(shù)含參構(gòu)造函數(shù)a=1復制構(gòu)造函數(shù)析構(gòu)函數(shù)析構(gòu)函數(shù)析構(gòu)函數(shù)四、完成程序填題(本大題共4個小題,每小題 3分,共12分)下面程序都留有空白,請將程序補充完整。1 .將如下程序補充完整。#include <iostream>using namespace std;class Testprivate:int num;public:Test(int num = 0) 1 this->num 或 Integer二num = nu

13、m; /初始化數(shù)據(jù)成員num為形參numint GetNum() const return num; ;int main()Test obj;cout << () << endl;return 0;)2 .將如下程序補充完整。#include <iostream>using namespace std;class Aprivate:int a;public:A(int m): a(m) void Show() const cout << a << endl; ;class B: Aprivate:int b;public:B(int

14、m, int n = 0):2 A(m), b(n) "/初始化數(shù)據(jù)成員值為nvoid Show() constA:Show();cout << b << endl;);int main()(B obj(8);();return 0;)3 .下列程序的輸出結(jié)果為:010試將程序補充完整。#include <iostream>using namespace std;class Point(private:int x, y;static int count;public:Point(int m = 0, int n = 0): x(m), y(n) c

15、ount+; Point() count-; int GetX() const return x; int GetY() const return y; static void ShowCount() cout << count << endl; /靜態(tài)數(shù)據(jù);3 int Point:count = 0; 成員的初始化為0int main()Point:ShowCount();Point *p = new Point;Point:ShowCount();delete p;Point:ShowCount();return 0;4 .將如下程序補充完整。#include &l

16、t;iostream>using namespace std;class Complexprivate:double realPart;double imagePart;public:Complex(double real = 0, double image = 0): realPart(real), imagePart(image) double GetRealPart() const return realPart; double GetImagePart() const return imagePart; 4 Complex operator+ (const Complex &am

17、p;a) const/重載加法運算符+Complex b;=this->realPart + ;=this->imagePart + ;return b;int main()Complex a(1,2), b(2, 6), c;c = a + b;cout << "a=" << () << "+”<<() << "i" << endl;cout << "b=" << () << "+”<&l

18、t;() << "i" << endl;cout << "c=" << () << "+”<<() << "i" << endl;return 0;五、編程題(本大題共 2小題,第1小題12分,第2小題16分,共28分)1 .編寫一個函數(shù)模板,用于求參數(shù)的絕對值,并編寫測試程序進行測試。函數(shù)模板聲明如下:template <class Type>Type Abs(Type a);2 .參考程序:#include <iostream>using namespace std;template <class Type>Type Abs(Type a)if (a >= 0) return a;else return - a;int main()cout << Abs(5) << endl;cout << Abs(-5) << endl;cout << Abs << endl;cout << Abs << endl;return 0;3 .定義一個復數(shù)類Complex,定義帶有2個

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 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

提交評論