版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、c+語言程序設(shè)計(jì) 期末考試試題及答案姓名 _ 學(xué)號(hào) _ 班號(hào) _ 題 號(hào)一二(1)二(2)三總 分成 績(jī)一、填空1在類中必須聲明成員函數(shù)的 原型 ,成員函數(shù)的 實(shí)現(xiàn) 部分可以寫在類外。2如果需要在被調(diào)函數(shù)運(yùn)行期間,改變主調(diào)函數(shù)中實(shí)參變量的值,則函數(shù)的形參應(yīng)該是 引用 類型或 指針 類型。3 抽象 類只能作為基類使用,而不能聲明它的對(duì)象。4進(jìn)行函數(shù)重載時(shí),被重載的同名函數(shù)如果都沒有用const修飾,則它們的形參 個(gè)數(shù) 或 類型 必須不同。5通過一個(gè) 常 對(duì)象只能調(diào)用它的常成員函數(shù),不能調(diào)用其他成員函數(shù)。6函數(shù)的遞歸調(diào)用是指函數(shù)直接或間接地調(diào)用 自身 。7拷貝構(gòu)造函數(shù)的形參必須是 本類對(duì)象的引用
2、。二、閱讀下列程序,寫出其運(yùn)行時(shí)的輸出結(jié)果 如果程序運(yùn)行時(shí)會(huì)出現(xiàn)錯(cuò)誤,請(qǐng)簡(jiǎn)要描述錯(cuò)誤原因。1請(qǐng)?jiān)谝韵聝深}中任選一題,該題得分即為本小題得分。如兩題都答,則取兩題得分之平均值為本小題得分。(1)程序:#include #include class base private: char msg30; protected: int n; public: base(char s,int m=0):n(m) strcpy(msg,s); void output(void) coutnendlmsgendl; ;class derived1:public baseprivate:int n;public:
3、derived1(int m=1):base(base,m-1) n=m; void output(void) coutnendl; base:output();class derived2:public derived1private:int n;public:derived2(int m=2):derived1(m-1) n=m; void output(void) coutnendl; derived1:output();int main()base b(base class,1);derived2 d;b.output();d.output();運(yùn)行結(jié)果:1base class210b
4、ase(2)程序:#include class samppublic:void setij(int a,int b)i=a,j=b;samp()coutdestroying.iendl;int getmuti()return i*j; protected:int i;int j;int main()samp *p;p=new samp5;if(!p)coutallocation errorn;return 1;for(int j=0;j5;j+)pj.setij(j,j);for(int k=0;k5;k+)coutmutik is: pk.getmuti()endl;deletep;retu
5、rn 0;運(yùn)行結(jié)果:muti0 is:0muti1 is:1muti2 is:4muti3 is:9muti4 is:16destroying.4destroying.3destroying.2destroying.1destroying.02請(qǐng)?jiān)谝韵聝深}中任選一題,該題得分即為本小題得分。如兩題都答,則取兩題得分之平均值為本小題得分。(1)程序:#include #include class vector public: vector(int s=100); int& elem(int ndx); void display(void); void set(void); vector(void
6、); protected: int size; int *buffer;vector:vector(int s)buffer=new intsize=s;int& vector:elem(int ndx)if(ndx=size)couterror in indexendl;exit(1);return bufferndx;void vector:display(void)for(int j=0; jsize; j+)coutelem(j)endl;void vector:set(void)for(int j=0; jsize; j+)elem(j)=j+1;vector:vector(void
7、)delete buffer;int main()vector a(10);vector b(a);a.set();b.display();運(yùn)行結(jié)果:12345678910最后出現(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)程序:#includeclass cat public: cat(); cat(const &cat); cat(); int getage() return *itsage; void setage( int age ) *itsage=age; protected: int * i
8、tsage;cat:cat()itsage=new int;*itsage=5;cat:cat()delete itsage;itsage=null;int main()cat a;coutas age:a.getage()endl;a.setage(6);cat b(a);coutas age:a.getage()endl;coutbs age:b.getage()endl;a.setage(7);coutas age:a.getage()endl;coutbs age:b.getage()endl;運(yùn)行結(jié)果:as age:5as age:6bs age:6as age:7bs age:7最
9、后出現(xiàn)錯(cuò)誤信息,原因是:聲明對(duì)象b是進(jìn)行的是淺拷貝,b與a共用同一個(gè)buffer,程序結(jié)束前調(diào)用析構(gòu)函數(shù)時(shí)對(duì)同一內(nèi)存區(qū)進(jìn)行了兩次釋放。三、閱讀下列程序及說明和注釋信息,在方框中填寫適當(dāng)?shù)某绦蚨?,使程序完成指定的功?程序功能說明:從鍵盤讀入兩個(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
10、 11 13 15 17 192 4 6 8 10 12 14 16 18 201 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20#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 node *deleteafter(
11、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ù) int position; / 當(dāng)前元素在表中的位置序號(hào)。由函數(shù)reset使用 node *getnode(const t& item,node *ptrnext=null); / 生成新節(jié)點(diǎn),數(shù)據(jù)域
12、為item,指針域?yàn)閜trnext void freenode(node *p); /釋放節(jié)點(diǎn) void copylist(const linkedlist& l); / 將鏈表l 拷貝到當(dāng)前表 /(假設(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)
13、const; /返回鏈表中元素個(gè)數(shù)(size) 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, 否則返回false int currentposition(void) const; /返回?cái)?shù)據(jù)成
14、員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)之后插入一個(gè)數(shù)據(jù)域?yàn)閕tem的節(jié)點(diǎn) t deletefront(void); /刪除頭節(jié)點(diǎn),釋放節(jié)點(diǎn)空間,更新prevptr、currptr和size void deleteat(vo
15、id); /刪除當(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 mergelist(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-dat
16、a()data() lc-insertrear(la-data(); la-deleteat(); else lc-insertrear(lb-data(); lb-deleteat(); while ( !la-listempty() ) lc-insertrear(la-data(); la-deleteat(); while ( !lb-listempty() ) lc-insertrear(lb-data(); lb-deleteat();int main() linkedlist la, lb, lc; int item, i;/讀如數(shù)據(jù)建立鏈表la for (i=0;i item;
17、 la.insertrear(item); la.reset();/讀如數(shù)據(jù)建立鏈表lb for (i=0;i item; lb.insertrear(item); lb.reset();mergelist(&la, &lb, &lc);/合并鏈表 lc.reset();/ 輸出各節(jié)點(diǎn)數(shù)據(jù),直到鏈表尾 while(!lc.endoflist() cout lc.data() ; lc.next(); / 使currptr指向下一個(gè)節(jié)點(diǎn) cout endl;if we dont do that it will go on and go on. we have to stop it; we nee
18、d 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 ivorian and
19、 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 of football and
20、 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) air up there watch mcayma
21、n 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 yaya toure, he told bbc sport.for m
22、e 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 footballs governing body, has also ordered an immedi
23、ate 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 aborted.the supersonic descent could happen as early as sund
24、a.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 through the lower level of the atmosphere (the troposphere)
25、 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 stratosphere. as he crosses the boundary layer (called the tropopause)
26、,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 becomes 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 jumpwhen he jumps, he is expected to reach the speed of sound
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 購買技術(shù)合作服務(wù)合同
- 全面消殺清潔協(xié)議
- 貨物買賣合同封
- 鋁板材料直銷協(xié)議
- 廣告服務(wù)合同樣式
- 裝修補(bǔ)充合同協(xié)議
- 軟件維護(hù)與運(yùn)維服務(wù)合同
- 長(zhǎng)期穩(wěn)定合作材料采購合同
- 臨時(shí)工與派遣公司合同
- 農(nóng)產(chǎn)品生鮮訂購合同
- 中心氣道介入治療ppt課件
- 部編版語文三年級(jí)下冊(cè)《綜合性學(xué)習(xí)-中華傳統(tǒng)節(jié)日》PPT課件公開課
- 建筑施工生產(chǎn)安全事故應(yīng)急救援預(yù)案
- 原子吸收光譜儀的結(jié)構(gòu)
- 高效全自動(dòng)凈水器操作使用說明
- (完整版)園林景觀工程進(jìn)度計(jì)劃?rùn)M道圖
- ppt素材――小圖標(biāo) 可直接使用
- 穿越220kV線路施工方案
- 2011辛卯年風(fēng)水布局概述
- 養(yǎng)殖戶糞污污染情況整改報(bào)告2篇
- Q-FT B039-2006汽車產(chǎn)品油漆涂層技術(shù)條件
評(píng)論
0/150
提交評(píng)論