電大C++語(yǔ)言程序設(shè)計(jì)期末考試試題及答案小抄參考

上傳人:仙*** 文檔編號(hào):30517129 上傳時(shí)間:2021-10-10 格式:DOC 頁(yè)數(shù):12 大?。?15.50KB
收藏 版權(quán)申訴 舉報(bào) 下載
電大C++語(yǔ)言程序設(shè)計(jì)期末考試試題及答案小抄參考_第1頁(yè)
第1頁(yè) / 共12頁(yè)
電大C++語(yǔ)言程序設(shè)計(jì)期末考試試題及答案小抄參考_第2頁(yè)
第2頁(yè) / 共12頁(yè)
電大C++語(yǔ)言程序設(shè)計(jì)期末考試試題及答案小抄參考_第3頁(yè)
第3頁(yè) / 共12頁(yè)

下載文檔到電腦,查找使用更方便

15 積分

下載資源

還剩頁(yè)未讀,繼續(xù)閱讀

資源描述:

《電大C++語(yǔ)言程序設(shè)計(jì)期末考試試題及答案小抄參考》由會(huì)員分享,可在線閱讀,更多相關(guān)《電大C++語(yǔ)言程序設(shè)計(jì)期末考試試題及答案小抄參考(12頁(yè)珍藏版)》請(qǐng)?jiān)谘b配圖網(wǎng)上搜索。

1、專業(yè)好文檔 C++語(yǔ)言程序設(shè)計(jì) 期末考試試題及答案 姓名 ____________ 學(xué)號(hào) ____________ 班號(hào) ___________ 題 號(hào) 一 二(1) 二(2) 三 總 分 成 績(jī) 一、填空 1.在類中必須聲明成員函數(shù)的 原型 ,成員函數(shù)的 實(shí)現(xiàn) 部分可以寫(xiě)在類外。 2.如果需要在被調(diào)函數(shù)運(yùn)行期間,改變主調(diào)函數(shù)中實(shí)參變量的值,則函數(shù)的形參應(yīng)該是 引用 類型或 指針 類型。 3. 抽象 類只能作為基類使用,而不能聲明它的對(duì)象。 4

2、.進(jìn)行函數(shù)重載時(shí),被重載的同名函數(shù)如果都沒(méi)有用const修飾,則它們的形參 個(gè)數(shù) 或 類型 必須不同。 5.通過(guò)一個(gè) 常 對(duì)象只能調(diào)用它的常成員函數(shù),不能調(diào)用其他成員函數(shù)。 6.函數(shù)的遞歸調(diào)用是指函數(shù)直接或間接地調(diào)用 自身 。 7.拷貝構(gòu)造函數(shù)的形參必須是 本類對(duì)象的引用 。 二、閱讀下列程序,寫(xiě)出其運(yùn)行時(shí)的輸出結(jié)果 如果程序運(yùn)行時(shí)會(huì)出現(xiàn)錯(cuò)誤,請(qǐng)簡(jiǎn)要描述錯(cuò)誤原因。 1.請(qǐng)?jiān)谝韵聝深}中任選一題,該題得分即為本小題得分。如兩題都答,則取兩題得分之平均值為本小題得分。 (1)程序: - 12 - #include

3、 #include class Base { private: char msg[30]; protected: int n; public: Base(char s[],int m=0):n(m) { strcpy(msg,s); } void output(void) { cout<

4、ic: Derived1(int m=1): Base("Base",m-1) { n=m; } void output(void) { cout<

5、 } }; int main() { Base B("Base Class",1); Derived2 D; B.output(); D.output(); } 運(yùn)行結(jié)果: 1 Base Class 2 1 0 Base (2)程序: #include class Samp {public: void Setij(int a,int b){i=a,j=b;} ~Samp() { cout<<"Destroying.."<

6、;} protected: int i; int j; }; int main() { Samp *p; p=new Samp[5]; if(!p) { cout<<"Allocation error\n"; return 1; } for(int j=0;j<5;j++) p[j].Setij(j,j); for(int k=0;k<5;k++) cout<<"Muti["<

7、 Muti[0] is:0 Muti[1] is:1 Muti[2] is:4 Muti[3] is:9 Muti[4] is:16 Destroying..4 Destroying..3 Destroying..2 Destroying..1 Destroying..0 2.請(qǐng)?jiān)谝韵聝深}中任選一題,該題得分即為本小題得分。如兩題都答,則取兩題得分之平均值為本小題得分。 (1)程序: #include #include class Vector { public: Vector(int s

8、=100); int& Elem(int ndx); void Display(void); void Set(void); ~Vector(void); protected: int size; int *buffer; }; Vector::Vector(int s) { buffer=new int[size=s]; } int& Vector::Elem(int ndx) { if(ndx<0||ndx>=size) { cout<<"error in index"<

9、l; exit(1); } return buffer[ndx]; } void Vector::Display(void) { for(int j=0; j

10、b(a); a.Set(); b.Display(); } 運(yùn)行結(jié)果: 1 2 3 4 5 6 7 8 9 10 最后出現(xiàn)錯(cuò)誤信息,原因是:聲明對(duì)象b是進(jìn)行的是淺拷貝,b與a共用同一個(gè)buffer,程序結(jié)束前調(diào)用析構(gòu)函數(shù)時(shí)對(duì)同一內(nèi)存區(qū)進(jìn)行了兩次釋放。 (2)程序: #include class CAT { public: CAT(); CAT(const &CAT); ~CAT(); int GetAge(){ return *itsAge; } void S

11、etAge( int age ) { *itsAge=age; } protected: int * itsAge; }; CAT::CAT() { itsAge=new int; *itsAge=5; } CAT::~CAT() { delete itsAge; itsAge=NULL; } int main() { CAT a; cout<<"as age:"<

12、out<<"bs age:"<

13、 程序功能說(shuō)明:從鍵盤(pán)讀入兩個(gè)分別按由小到大次序排列的整數(shù)序列,每個(gè)序列10個(gè)整數(shù),整數(shù)間以空白符分隔。用這兩個(gè)序列分別構(gòu)造兩個(gè)單鏈表,每個(gè)鏈表有10個(gè)結(jié)點(diǎn),結(jié)點(diǎn)的數(shù)據(jù)分別按由小到大次序排列。然后將兩個(gè)鏈表合成為一個(gè)新的鏈表,新鏈表的結(jié)點(diǎn)數(shù)據(jù)仍然按由小到大次序排列。最后按次序輸出合并后新鏈表各結(jié)點(diǎn)的數(shù)據(jù)。 程序運(yùn)行結(jié)果如下,帶下劃線部分表示輸入內(nèi)容,其余是輸出內(nèi)容: 1 3 5 7 9 11 13 15 17 19 2 4 6 8 10 12 14 16 18 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

14、#include #include //類定義部分 template class Node { private: Node *next; //指向后繼節(jié)點(diǎn)的指針 public: T data; //數(shù)據(jù)域 Node (const T& item, Node* ptrnext = NULL); // 構(gòu)造函數(shù) void InsertAfter(Node *p); //在本節(jié)點(diǎn)之后插入一個(gè)同類節(jié)點(diǎn)p

15、 Node *DeleteAfter(void); //刪除本節(jié)點(diǎn)的后繼節(jié)點(diǎn),返回其地址 Node *NextNode(void) const; // 獲取后繼節(jié)點(diǎn)的地址 }; template class LinkedList { private: Node *front, *rear; // 表頭和表尾指針 Node *prevPtr, *currPtr; //記錄表當(dāng)前遍歷位置的指針,由插入和刪除操作更新 int size; // 表中的元素個(gè)數(shù)

16、int position; // 當(dāng)前元素在表中的位置序號(hào)。由函數(shù)Reset使用 Node *GetNode(const T& item,Node *ptrNext=NULL); // 生成新節(jié)點(diǎn),數(shù)據(jù)域?yàn)閕tem,指針域?yàn)閜trNext void FreeNode(Node *p); //釋放節(jié)點(diǎn) void CopyList(const LinkedList& L); // 將鏈表L 拷貝到當(dāng)前表

17、 //(假設(shè)當(dāng)前表為空)。被拷貝構(gòu)造函數(shù)、operator=調(diào)用 public: LinkedList(void); // 構(gòu)造函數(shù) LinkedList(const LinkedList& L); //拷貝構(gòu)造函數(shù) ~LinkedList(void); // 析構(gòu)函數(shù) LinkedList& operator= (const LinkedList& L);//重載賦值運(yùn)算符 int ListSize(void) const; //返回鏈表中元素個(gè)數(shù)(size)

18、 int ListEmpty(void) const; //size為0時(shí)返回TRUE,否則返回FALSE void Reset(int pos = 0); //將指針currPtr移動(dòng)到序號(hào)為pos的節(jié)點(diǎn), //prevPtr相應(yīng)移動(dòng),position記錄當(dāng)前節(jié)點(diǎn)的序號(hào) void Next(void); //使prevPtr和currPtr移動(dòng)到下一個(gè)節(jié)點(diǎn) int EndOfList(void) const; // currPtr等于NULL時(shí)返回TRUE, 否則返回FA

19、LSE int CurrentPosition(void) const; //返回?cái)?shù)據(jù)成員position void InsertFront(const T& item); //在表頭插入一個(gè)數(shù)據(jù)域?yàn)閕tem的節(jié)點(diǎn) void InsertRear(const T& item); //在表尾添加一個(gè)數(shù)據(jù)域?yàn)閕tem的節(jié)點(diǎn) void InsertAt(const T& item); //在當(dāng)前節(jié)點(diǎn)之前插入一個(gè)數(shù)據(jù)域?yàn)閕tem的節(jié)點(diǎn) void InsertAfter(const T& item); //在當(dāng)前節(jié)點(diǎn)之后插入

20、一個(gè)數(shù)據(jù)域?yàn)閕tem的節(jié)點(diǎn) T DeleteFront(void); //刪除頭節(jié)點(diǎn),釋放節(jié)點(diǎn)空間,更新prevPtr、currPtr和size void DeleteAt(void); //刪除當(dāng)前節(jié)點(diǎn),釋放節(jié)點(diǎn)空間,更新prevPtr、currPtr和size T& Data(void); // 返回對(duì)當(dāng)前節(jié)點(diǎn)成員data的引用 void ClearList(void); // 清空鏈表:釋放所有節(jié)點(diǎn)的內(nèi)存空間。 }; //類實(shí)現(xiàn)部分略...... template void MergeLis

21、t(LinkedList* la, LinkedList* lb,LinkedList* lc) { //合并鏈表la和lb,構(gòu)成新鏈表lc。 //函數(shù)結(jié)束后,程序的數(shù)據(jù)所占內(nèi)存空間總數(shù)不因此函數(shù)的運(yùn)行而增加。 while ( !la->ListEmpty() &&!lb->ListEmpty()) { if (la->Data()<=lb->Data()) { lc->InsertRear(la->Data()); la->DeleteAt(); } else

22、 { lc->InsertRear(lb->Data()); lb->DeleteAt(); } } while ( !la->ListEmpty() ) { lc->InsertRear(la->Data()); la->DeleteAt(); } while ( !lb->ListEmpty() ) { lc->InsertRear(lb->Data()); lb->DeleteAt(); }

23、 } int main() { LinkedList la, lb, lc; int item, i; //讀如數(shù)據(jù)建立鏈表la for (i=0;i < 10;i++) { cin>>item; la.InsertRear(item); } la.Reset(); //讀如數(shù)據(jù)建立鏈表lb for (i=0;i < 10;i++) { cin>>item; lb.InsertRear(item); }

24、 lb.Reset(); MergeList(&la, &lb, &lc);//合并鏈表 lc.Reset(); // 輸出各節(jié)點(diǎn)數(shù)據(jù),直到鏈表尾 while(!lc.EndOfList()) { cout <

25、ed the courage to do it." His comments came hours after Fifa vice-president Jeffrey Webb - also in London for the FAs celebrations - said he wanted to meet Ivory Coast international Toure to discuss his complaint. CSKA general director Roman Babaev says the matter has been "exaggerated" by the Iv

26、orian and the British media. Blatter, 77, said: "It has been decided by the Fifa congress that it is a nonsense for racism to be dealt with with fines. You can always find money from somebody to pay them. "It is a nonsense to have matches played without spectators because it is against the spirit

27、of football and against the visiting team. It is all nonsense. "We can do something better to fight racism and discrimination. "This is one of the villains we have today in our game. But it is only with harsh sanctions that racism and discrimination can be washed out of football." The (lack of) a

28、ir up there Watch mCayman Islands-based Webb, the head of Fifas anti-racism taskforce, is in London for the Football Associations 150th anniversary celebrations and will attend Citys Premier League match at Chelsea on Sunday. "I am going to be at the match tomorrow and I have asked to meet

29、Yaya Toure," he told BBC Sport. "For me its about how he felt and I would like to speak to him first to find out what his experience was." Uefa hasopened disciplinary proceedings against CSKAfor the "racist behaviour of their fans" duringCitys 2-1 win. Michel Platini, president of European footba

30、lls governing body, has also ordered an immediate investigation into the referees actions. CSKA said they were "surprised and disappointed" by Toures complaint. In a statement the Russian side added: "We found no racist insults from fans of CSKA." Baumgartner the disappointing news: Mission aborte

31、d. The supersonic descent could happen as early as Sunda. The weather plays an important role in this mission. Starting at the ground, conditions have to be very calm -- winds less than 2 mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule attached, will move

32、through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will climb higher than the tip of Mount Everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratospher

33、e. As he crosses the boundary layer (called the tropopause),e can expect a lot of turbulence. The balloon will slowly drift to the edge of space at 120,000 feet ( Then, I would assume, he will slowly step out onto something resembling an Olympic diving platform. Below, the Earth become

34、s the concrete bottom of a swimming pool that he wants to land on, but not too hard. Still, hell be traveling fast, so despite the distance, it will not be like diving into the deep end of a pool. It will be like he is diving into the shallow end. Skydiver preps for the big jump When he jumps, he

35、is expected to reach the speed of sound -- 690 mph (1,110 kph) -- in less than 40 seconds. Like hitting the top of the water, he will begin to slow as he approaches the more dense air closer to Earth. But this will not be enough to stop him completely. If he goes too fast or spins out of control,

36、he has a stabilization parachute that can be deployed to slow him down. His team hopes its not needed. Instead, he plans to deploy his 270-square-foot (25-square-meter) main chute at an altitude of around 5,000 feet (1,524 meters). In order to deploy this chute successfully, he will have to slow to

37、 172 mph (277 kph). He will have a reserve parachute that will open automatically if he loses consciousness at mach speeds. Even if everything goes as planned, it wont. Baumgartner still will free fall at a speed that would cause you and me to pass out, and no parachute is guaranteed to work higher than 25,000 feet (7,620 meters). cause there

展開(kā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. 裝配圖網(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ì)自己和他人造成任何形式的傷害或損失。

相關(guān)資源

更多
正為您匹配相似的精品文檔
關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號(hào):ICP2024067431號(hào)-1 川公網(wǎng)安備51140202000466號(hào)


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺(tái),本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請(qǐng)立即通知裝配圖網(wǎng),我們立即給予刪除!

五月丁香婷婷狠狠色,亚洲日韩欧美精品久久久不卡,欧美日韩国产黄片三级,手机在线观看成人国产亚洲