電大形成性考核冊(cè)c++第四次作業(yè)及答案_第1頁(yè)
電大形成性考核冊(cè)c++第四次作業(yè)及答案_第2頁(yè)
電大形成性考核冊(cè)c++第四次作業(yè)及答案_第3頁(yè)
電大形成性考核冊(cè)c++第四次作業(yè)及答案_第4頁(yè)
電大形成性考核冊(cè)c++第四次作業(yè)及答案_第5頁(yè)
已閱讀5頁(yè),還剩5頁(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、計(jì)算機(jī)應(yīng)用專(zhuān)業(yè)“c+語(yǔ)言程序設(shè)計(jì)”課程作業(yè)第四次作業(yè)一、 填空題1. 在定義類(lèi)對(duì)象的語(yǔ)句執(zhí)行時(shí),系統(tǒng)在建立每個(gè)對(duì)象的過(guò)程中將自動(dòng)調(diào)用該類(lèi)的_構(gòu)造函數(shù)_使其初始化。2. 當(dāng)一個(gè)類(lèi)對(duì)象被撤消時(shí)將自動(dòng)調(diào)用該類(lèi)的_析構(gòu)函數(shù)_。3. 對(duì)基類(lèi)數(shù)據(jù)成員的初始化是通過(guò)執(zhí)行派生類(lèi)構(gòu)造函數(shù)中的_初始化表_來(lái)實(shí)現(xiàn)的。4. 對(duì)一個(gè)類(lèi)中的數(shù)據(jù)成員的初始化可以通過(guò)構(gòu)造函數(shù)中的_初始化表_實(shí)現(xiàn),也可以通過(guò)構(gòu)造函數(shù)中的_賦值語(yǔ)句_實(shí)現(xiàn)。5. 在一個(gè)派生類(lèi)中,對(duì)基類(lèi)成員、類(lèi)對(duì)象成員和非類(lèi)對(duì)象成員的初始化次序的先基類(lèi)成員,后類(lèi)對(duì)象成員,最后非對(duì)象成員。6. 當(dāng)撤消一個(gè)含有基類(lèi)和類(lèi)對(duì)象成員的派生類(lèi)對(duì)象時(shí),將首先完成派生類(lèi)本身的析構(gòu)

2、函數(shù)定義體的執(zhí)行,接著完成類(lèi)對(duì)象成員的析構(gòu)函數(shù)定義體的執(zhí)行,最后完成基類(lèi)成員的析構(gòu)函數(shù)定義體的執(zhí)行。7. 設(shè)px是指向一個(gè)類(lèi)動(dòng)態(tài)對(duì)象的指針變量,則執(zhí)行“delete px;”語(yǔ)句時(shí),將自動(dòng)調(diào)用該類(lèi)的析構(gòu)函數(shù)。8. 當(dāng)一個(gè)類(lèi)對(duì)象離開(kāi)它的作用域時(shí),系統(tǒng)將自動(dòng)調(diào)用該類(lèi)的析構(gòu)函數(shù)。9. 假定一個(gè)類(lèi)對(duì)象數(shù)組為an,當(dāng)離開(kāi)它的作用域時(shí),系統(tǒng)自動(dòng)調(diào)用該類(lèi)析構(gòu)函數(shù)的次數(shù)為n次。10. 假定ab為一個(gè)類(lèi),則執(zhí)行“ab a10;”語(yǔ)句時(shí),系統(tǒng)自動(dòng)調(diào)用該類(lèi)構(gòu)造函數(shù)的次數(shù)為10次。11. 假定擁護(hù)沒(méi)有給一個(gè)名為ab的類(lèi)定義構(gòu)造函數(shù),則系統(tǒng)為其隱含定義的構(gòu)造函數(shù)為空構(gòu)造函數(shù)。12. 假定用戶沒(méi)有給一個(gè)名為ab的類(lèi)定義析

3、構(gòu)函數(shù),則系統(tǒng)為其隱含定義的析構(gòu)函數(shù)為空析構(gòu)函數(shù)。13. 若需要把一個(gè)函數(shù)“void f(); ”定義為一個(gè)類(lèi)ab的友元函數(shù),則應(yīng)在類(lèi)ab的定義中加入一條語(yǔ)句:friend void f();。14. 若需要把一個(gè)類(lèi)ab定義為一個(gè)類(lèi)cd的友元類(lèi),則應(yīng)在類(lèi)cd的定義中加入一條語(yǔ)句:friend class ab;。15. 假定一個(gè)類(lèi)ab中有一個(gè)靜態(tài)整型成員bb,在類(lèi)外為它進(jìn)行定義并初始化為0時(shí),所使用寫(xiě)法為ab:bb = 0;。16. 假定類(lèi)ab中有一個(gè)公用屬性的靜態(tài)數(shù)據(jù)成員bb,在類(lèi)外不通過(guò)對(duì)象名訪問(wèn)該成員 bb的寫(xiě)法為ab:bb。17. 當(dāng)類(lèi)中一個(gè)字符指針成員指向具有n個(gè)字節(jié)的儲(chǔ)存空間時(shí),它

4、所能儲(chǔ)存字符串的最大長(zhǎng)度為n-1。18. 假定ab為一個(gè)類(lèi),則該類(lèi)的拷貝構(gòu)造函數(shù)的聲明語(yǔ)句為ab:ab(ab &)。19. 對(duì)類(lèi)對(duì)象成員初始化是通過(guò)執(zhí)行構(gòu)造函數(shù)中的初始化表完成的。20. 對(duì)于類(lèi)中定義的成員,其隱含訪問(wèn)權(quán)限為private,對(duì)于結(jié)構(gòu)中定義的成員,其隱含訪問(wèn)權(quán)限為public。21. 一個(gè)類(lèi)的友元函數(shù)或友元類(lèi)能夠通過(guò)成員操作符訪問(wèn)該類(lèi)的所有數(shù)據(jù)成員和函數(shù)成員。22. 假定要對(duì)類(lèi)ab定義加號(hào)操作符重載成員函數(shù),實(shí)現(xiàn)兩個(gè)ab類(lèi)對(duì)象的加法,并返回相加結(jié)果,則該成員函數(shù)的聲明語(yǔ)句為:ab operator +(ab, ab);。23. 在c+流類(lèi)庫(kù)中,根基類(lèi)為ios。24. 在c+流類(lèi)庫(kù)

5、中,輸入流類(lèi)和輸出流類(lèi)的名稱(chēng)分別為istream和ostream。25. 若要在程序文件中進(jìn)行標(biāo)準(zhǔn)輸入輸出操作,則必須在開(kāi)始的#inlude命令中使用iosteam.h頭文件。26. 若要在程序文件中進(jìn)行文件輸入輸出操作,則必須在開(kāi)始的#inlude命令中使用fstream.h頭文件。27. 當(dāng)從字符文件中讀取回車(chē)和換行兩個(gè)字符時(shí),被系統(tǒng)看作為一個(gè)換行符。28. 當(dāng)使用ifstream流類(lèi)定義一個(gè)流對(duì)象并打開(kāi)一個(gè)磁盤(pán)文件時(shí),文件的隱含打開(kāi)方式為 讀取的文本文件,當(dāng)使用ofstream 流類(lèi)定義一個(gè)流對(duì)象并打開(kāi)一個(gè)磁盤(pán)文件時(shí),文件的隱含打開(kāi)方式為寫(xiě)入的文本文件。29. 當(dāng)需要使用istrstre

6、am流類(lèi)定義一個(gè)流對(duì)象并聯(lián)系一個(gè)字符串時(shí),應(yīng)在文件開(kāi)始使用#include命令,使之包含strstrea.h文件。二給出下列程序運(yùn)行后的輸出結(jié)果1#includeclass aint a, b;public: a( ) a=b=0;a( int aa, int bb) a=aa; b=bb; couta bendl;void main( ) a x,y(6,3), z(8,10);6 38 102#includeclass aint a, b;public:a(int aa= 0, int bb= 0): a(aa),b(bb)coutconstructor! a + bendl;void m

7、ain()a x, y(2,5), z(y);constructor!0constructor!73#includeclass aint * a;public:a(int aa= 0)a = new int(aa);coutconstructor! * aendl;void main()a x2;a * p = new a(5);delete p;constructor!0constructor!0constructor!54#includeclass aint a;public:a(int aa= 0): a(aa)a()coutdestructor! a endl; void main()

8、a x(5);a * p = new a(10);delete p;destructor!10destructor!55#includeclass a int * a;public:a(int x)a = new int(x);coutconstructor! * aendl;a()delete a;coutdestructor!endl;void main()a x(9),* p;p = new a(12);delete p;constructor!9constructor!12destructor!destructor!6#includeclass aint a;public:a(int

9、aa= 0): a(aa)coutconstructor a! aendl;class b:public aint b;public:b(int aa, int bb): a(aa), b(bb)coutconstructor b! bendl;void main()b x(2,3),y(4,5);constructor a!2constructor b!3constructor a!4constructor b!57#includeclass aint a;public:a(int aa= 0)a = aa;a()coutdestructor a! aendl;class b:public

10、aint b;public:b(int aa= 0, int bb= 0): a(aa)b = bb;b()coutdestructor b!bendl;void main()b x(5),y(6,7);deconstructor b!7deconstructor a!6deconstructor b!0deconstructor a!58#include#includeclass aint a,b;char op;public:a(int aa, int bb, char ch)a = aa;b = bb;op = ch;int comp()switch(op)case + :return

11、a + b;case - :return a - b;case * :return a * b;case / :if(b!=0)return a/b;else exit(1);case % :if(b!=0)return a%b;else exit(1);default:exit(1);void seta(int aa, int bb, char ch)a = aa;b = bb;op = ch;void main(void)a x(3,5,*);int a = x.comp();x. seta(4,9, +);a += x.comp();x. seta(13,8, %);a += x.com

12、p();couta=aendl;a=339#includeclass bint a,b;public:b()a = b = 0;b(int aa, int bb)a = aa;b = bb;b operator +(b& x)b r;r . a = a + x . a;r . b = b + x . b;return r;b operator -(b& x)b r;r . a = a - x . a;r . b = b - x . b;return r;void outb()cout a b endl;void main()b x(6,5),y(13,3), z1, z2;z1 = x + y

13、;z2 = x - y;z1.outb();z2.outb();19 8-7 210#includetemplateclass fftt a1,a2,a3;public:ff(tt b1, tt b2, tt b3)a1 =b1;a2 =b2;a3 =b3;tt sum()return a1 + a2 + a3;void main()ff x(8,3,4),y(5,9,11);cout x. sum() y. sum()endl;15 25二、 寫(xiě)出下列每個(gè)函數(shù)的功能1include include include void ja(char * fname) / /可以把fname所指字符串作

14、為文件標(biāo)識(shí)符的文件稱(chēng)為fname文件ofstream fout(fname);char a20;cin a;whlie(strcmp(a,”end”)!=0)fout a a;將鍵盤(pán)輸入的字符串(上限為19個(gè)字符)寫(xiě)入到fname文件中。2include include void jb(char * fname) / /可把以fname所指字符串作為文件標(biāo)識(shí)符的文件稱(chēng)為fname文件 / /假定該文件中保存著一批字符串,每個(gè)字符串的長(zhǎng)度均小于20。 ifstream fin(fname);char a20;int i = 0;whlie(fin a)cout a endl;i + +;fin.

15、close();cout ”i = ” i endl;將fname文件輸出到標(biāo)準(zhǔn)輸出流(屏幕)上,最后顯示字符串的數(shù)量。3include include void jc(chat * fname, int n) / /可把以fname所指字符串作為文件標(biāo)識(shí)符的文件稱(chēng)為fname文件ofstream fout(fname, ios : : out | ios : : binary);int x;for(int i = 0;i x;fout.write(char * )&x, sizeof(x);fout.close();從鍵盤(pán)輸入n個(gè)數(shù),并以二進(jìn)制的方式寫(xiě)到fname文件中。4includein

16、cludevoid jd(char * fname) / /可把以fname所指字符串作為文件標(biāo)識(shí)符的文件稱(chēng)為fname文件, / /假定該文件保存著一批整數(shù)。ifstream fin(fname, ios : : in | ios : : nocreate | ios : : binary);int x, s = 0, n = 0;whlie(fin.read(char * )&x, sizeof(x)s + = x;n + +;cout n s float(s)/nendl;fin.close();輸出fname文件中保存的整數(shù)的個(gè)數(shù)、總加值以及平均值。if we dont do that

17、 it will go on and go on. we have to stop it; we need 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 say

18、s the matter has been exaggerated by the ivorian 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 spectat

19、ors because it is against the spirit 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

20、 of football.the (lack of) air 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 ha

21、ve asked to meet 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

22、footballs 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 aborted.

23、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 through

24、 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 stratosphere. as h

25、e 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 becomes the concrete bottom o

26、f 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 - 690 mph (1,110 kph) - 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. 人人文庫(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)論