




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、成績(jī)上海大學(xué)20142015學(xué)年度秋季學(xué)期試卷(A卷)課程名:面向?qū)ο蟪绦蛟O(shè)計(jì)課程號(hào):學(xué)分:5應(yīng)試人聲明:我保證遵守上海大學(xué)學(xué)生手冊(cè)中的上海大學(xué)考場(chǎng)規(guī)則,如有考試違紀(jì)、作弊行為,愿意接受上海大學(xué)學(xué)生考試違紀(jì)、作弊行為界定及處分規(guī)定的紀(jì)律處分。應(yīng)試人應(yīng)試人學(xué)號(hào)應(yīng)試人所在院系題號(hào)一(20)二(30)三(25)四(25)得分得分一、判斷題(每小題2分,共20分)1.引用在聲明時(shí)必須對(duì)其初始化,以綁定某個(gè)已經(jīng)存在的變量(或?qū)ο螅?,在該引用的生命期?nèi),該綁定不能被更改。()2.指針變量在定義時(shí)必須對(duì)其初始化,以鎖定某個(gè)已經(jīng)存在的目標(biāo)變量(或?qū)ο螅谠撝羔樧兞康纳趦?nèi),該指向不能被更改。()3.值返回
2、的函數(shù)(如:doublesqrt(double);)的調(diào)用表達(dá)式(如:sqrt(2.0))代表一個(gè)無(wú)名的臨時(shí)變量(或?qū)ο螅?,一般不將其用作左值?)4.引用返回的函數(shù),可以返回該函數(shù)中值傳遞的形參變量(或?qū)ο螅?)5.任何類都有構(gòu)造函數(shù)、復(fù)制構(gòu)造函數(shù)、析構(gòu)函數(shù)、賦值運(yùn)算符函數(shù)。()6.有靜態(tài)數(shù)據(jù)成員的類,一般地應(yīng)該考慮為其設(shè)計(jì)復(fù)制構(gòu)造函數(shù)、析構(gòu)函數(shù)。()7.將用于輸出的插入運(yùn)算符函數(shù)operator設(shè)計(jì)成友元函數(shù)的根本原因是因?yàn)檫M(jìn)行輸出操作時(shí)需要訪問(wèn)對(duì)象的內(nèi)部數(shù)據(jù)成員。()8.在C+程序中,操作符new的功能與calloc函數(shù)的功能完全一樣。()9.創(chuàng)建一個(gè)C+字符串對(duì)象(如:strings
3、tr;),則sizeof(str)的值等于str.length()的值。其中成員函數(shù)length為返回字符串的長(zhǎng)度。()10.基類的私有數(shù)據(jù)成員在派生類中是存在的,但不可直接訪問(wèn),需要用從基類繼承下來(lái)的函數(shù)訪問(wèn)。()得分二、填空題(每空2分,共30分)如下設(shè)計(jì)了結(jié)點(diǎn)類Node、鏈表類LinkList,并將鏈表類作為結(jié)點(diǎn)類的友類,請(qǐng)根據(jù)運(yùn)行結(jié)果,完成程序。#includeusingnamespacestd;classLinkList;/提前聲明classNodepublic:Node(intx=0):data(x)friendclassLinkList;private:intdata;Node*
4、next;classLinkListprivate:Node*head;public:LinkList(intn=0,int*array=NULL)Node*p;head=NULL;for(inti=n-1;i=0;i-)p=newNode;p-data=(array!=NULL)?arrayi:0;p-next=head;head=p;LinkList(constLinkList&link)head=NULL;*this=link;virtualLinkList()FreeList();LinkList&operator=(constLinkList&link)if(&link=this)r
5、eturn*this;FreeList();Node*p,*q;for(p=link.head;p!=NULL;p=p-next)if(head=NULL)head=q=newNode(p-data);elseq-next=newNode(p-data);q=q-next;q-next=NULL;return*this;voidFreeList()Node*p;while(head!=NULL)p=head;head=head-next;deletep;voidShowList(ostream&out)constoutnext)outdata;outNULL;ostream&operator3
6、-7-2-1-NULLhead-3-7-2-1-NULLhead-NULLhead-3-7-2-1-NULLlink.ShowList(out);returnout;intmain()intn,a=3,7,2,1;n=sizeof(a)/sizeof(*a);LinkListlinkA(n,a),linkB(linkA),linkC;coutlinkAnlinkBnlinkCendl;linkC=linkA;coutlinkCendl;return0;得分三、閱讀程序?qū)懗鲞\(yùn)行結(jié)果(每行1分,共25分)1.(7分)有關(guān)構(gòu)造與析構(gòu)的順序#includeusingnamespacestd;class
7、Testpublic:Test(inta=0,intb=0):x(a),y(b)Test()if(x=y)cout數(shù)據(jù)成員的值相同,都等于xendl;elsecout數(shù)據(jù)成員的值不同,分別為x,yendl;friendostream&operator(ostream&out,constTest&t)out(t.x,t.y);returnout;運(yùn)行結(jié)果(1)(10,0)(0,0)(2,3)數(shù)據(jù)成員的值不同,分別為10,0退出程序,返回操作系統(tǒng)數(shù)據(jù)成員的值不同,分別為2,3數(shù)據(jù)成員的值相同,都等于0private:intx,y;intmain()Test*p,t1;p=newTest(10);T
8、estt2(2,3);cout*pnt1nt2endl;deletep;cout退出程序,返回操作系統(tǒng)endl;return0;2.以下兩小題所涉及的類設(shè)計(jì),頭文件如下。/test.h#include#includeusingnamespacestd;classBASEpublic:BASE(doublex=0,doubley=0):_x(x),_y(y)virtualvoidShow(ostream&out)const=0;protected:double_x,_y;ostream&operator(ostream&out,constBASE&x)x.Show(out);returnout;
9、classComplex:publicBASEpublic:Complex(doublex=0,doubley=0):BASE(x,y)voidShow(ostream&out)constif(_x!=0)out0)out+_yi;elseif(_y0)out-_yi;elseif(_y!=0)cout_yi;elsecout_x;friendComplexoperator+(constComplex&a,constComplex&b)Complexc;c._x=a._x+b._x;c._y=a._y+b._y;returnc;friendComplexoperator*(constCompl
10、ex&a,constComplex&b)Complexc;c._x=a._x*b._x-a._y*b._y;c._y=a._x*b._y+a._y*b._x;returnc;doubleabs()returnsqrt(_x*_x+_y*_y);classPoint:publicBASEpublic:Point(doublex=0,doubley=0):BASE(x,y)voidShow(ostream&out)constout(_x,_y);friendPointoperator+(constPoint&a,constPoint&b)Pointc;c._x=a._x+b._x;c._y=a._
11、y+b._y;returnc;運(yùn)行結(jié)果(2.1)1+2i3+4i1i10y.abs():54+6i-5+10i(1,2)(3,4)(4,6)2.1(10分)測(cè)試程序#includetest.hintmain()Complexx(1,2),y(3,4),z1(0,1),z2(10);coutxnynz1nz2endl;couty.abs():y.abs()endl;z1=x+y;z2=x*y;coutz1nz2endl;Pointa(1,2),b(3,4);coutanbendl;couta+bendl;return0;2.2(8分)測(cè)試程序#includetest.hintmain()運(yùn)行結(jié)果
12、(2.2)1+2i6+2i5+10i2+4i(1,2)(2,2)(2,2)(4,8)Complexx(1,2),y,z;y=5+x;z=5*x;coutxnynzendl;coutx+xendl;Pointa(1,2),b,c;b=a+1;c=1+a;coutanbncendl;a=a+a;couta+aendl;return0;得分四、完成如下類的設(shè)計(jì)(25分)在GCC編譯系統(tǒng)中,unsignedlonglong數(shù)據(jù)類型使整型數(shù)的取值范圍得到擴(kuò)展(,即0)。為了進(jìn)一步擴(kuò)展非負(fù)整數(shù)的取值范圍設(shè)計(jì)了如下的類。該類數(shù)據(jù)可精確計(jì)算至,可處理3637位非負(fù)十進(jìn)制整數(shù)。請(qǐng)?jiān)陬惖穆暶黧w外實(shí)現(xiàn)5個(gè)尚未定義的
13、成員函數(shù)或友元函數(shù)。最后寫出程序的運(yùn)行結(jié)果(每個(gè)函數(shù)定義4分,運(yùn)行結(jié)果5分)。/LLINT.h頭文件#ifndefLLINT_H#defineLLINT_H#includeusingnamespacestd;classLLINTpublic:LLINT(unsignedlonglongx0=0,unsignedlonglongx1=0);/第一參數(shù)為低位LLINT(constchar*str);LLINT&operator+();LLINToperator+(int);friendLLINToperator+(constLLINT&x1,constLLINT&x2);LLINT&operato
14、r+=(constLLINT&x);friendostream&operator(istream&in,LLINT&x);friendbooloperator(constLLINT&x1,constLLINT&x2);friendbooloperator=(constLLINT&x1,constLLINT&x2);friendbooloperator(constLLINT&x1,constLLINT&x2);friendbooloperator=(constLLINT&x1,constLLINT&x2);friendbooloperator=(constLLINT&x1,constLLINT&
15、x2);friendbooloperator!=(constLLINT&x1,constLLINT&x2);protected:staticconstunsignedlonglongBBILLION;unsignedlonglonga1,a0;/a1*+a0可表示3637位十進(jìn)制非負(fù)整數(shù);#endif/LLINT.cpp源程序文件#includeLLINT.h#includeconstunsignedlonglongLLINT:BBILLION=/靜態(tài)常量數(shù)據(jù)成員的定義及初始化(1018)LLINT:LLINT(unsignedlonglongx0,unsignedlonglongx1)/構(gòu)造
16、函數(shù)unsignedlonglongx=x0/BBILLION;a0=x0%BBILLION;a1=x1+x;LLINT:LLINT(constchar*str)/轉(zhuǎn)換構(gòu)造函數(shù)(從C-字符串轉(zhuǎn)換)*this=atoLLINT(str);/直接利用成員函數(shù)實(shí)現(xiàn)轉(zhuǎn)換構(gòu)造LLINTLLINT:operator+(int)/后增量運(yùn)算符函數(shù)LLINTtemp(*this);+(*this);returntemp;LLINToperator+(constLLINT&x1,constLLINT&x2)LLINTs;unsignedlonglongc=x1.a0+x2.a0;s.a0=c%LLINT:BBI
17、LLION;s.a1=x1.a1+x2.a1+c/LLINT:BBILLION;returns;ostream&operator(ostream&out,constLLINT&x)if(x.a1!=0)outx.a1setfill(0)setw(18)x.a0setfill();elseout(istream&in,LLINT&x)charstr200;instr;x=atoLLINT(str);returnin;booloperator(constLLINT&x1,constLLINT&x2)if(x1.a1x2.a1)returntrue;elseif(x1.a1=x2.a1)return
18、x1.a0x2.a0;elsereturnfalse;booloperator(constLLINT&x1,constLLINT&x2)if(x1.a1x2.a1)returntrue;elseif(x1.a1=x2.a1)returnx1.a0x2.a0;elsereturnfalse;booloperator=(constLLINT&x1,constLLINT&x2)if(x1.a1x2.a1)returntrue;elseif(x1.a1=x2.a1)returnx1.a0=0;i-)if(0=stri&stri=9)if(j18)x.a0+=p0*(stri-0);p0*=10;elseif(j36)x.a1+=p1*(stri-0);p1*=10;j+;returnx;/LLINT_test.cpp測(cè)試程序#includeLLINT.hintmain()LLINTx(321),y(100),z;coutxnynzendl;z=;coutz+endl;coutz=(constL
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度宅基地子女贈(zèng)與及后續(xù)土地開發(fā)利用合同
- 2025年甘肅有色冶金職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)技能測(cè)試題庫(kù)及參考答案
- 2025年度房地產(chǎn)租賃合同管理及市場(chǎng)調(diào)控合同
- 2025年度三方委托付款與物流運(yùn)輸合同
- 2025年度XX小區(qū)供熱設(shè)施安全評(píng)估與供用熱力合同
- 2025年度養(yǎng)老機(jī)構(gòu)委托經(jīng)營(yíng)管理協(xié)議
- 2025年度新能源汽車合伙項(xiàng)目退股協(xié)議書
- 2025年度學(xué)校學(xué)生資助項(xiàng)目合同協(xié)議
- 2025年度國(guó)際學(xué)校辦學(xué)許可引進(jìn)與轉(zhuǎn)讓合同
- 2025年湖北省鄂州市單招職業(yè)適應(yīng)性測(cè)試題庫(kù)帶答案
- 2024年廣東省《輔警招聘考試必刷500題》考試題庫(kù)含必背答案
- 餐飲企業(yè)牛奶產(chǎn)品推廣方案
- 2025年中國(guó)南光集團(tuán)有限公司招聘筆試參考題庫(kù)含答案解析
- 工程造價(jià)鑒定申請(qǐng)書
- 五年級(jí)下冊(cè)數(shù)學(xué)北師大版課件練習(xí)一
- 《房屋建筑發(fā)展史》課件
- 第6章平面圖形的初步認(rèn)識(shí)數(shù)學(xué)探究雞蛋餅的分割教案2024-2025學(xué)年蘇科版(2024)七年級(jí)數(shù)學(xué)上冊(cè)
- 如何開展中醫(yī)護(hù)理技術(shù)
- 麻醉、精神藥品培訓(xùn)課件
- 新媒體導(dǎo)論彭蘭課件
- 安全生產(chǎn)管理制度匯編(一般化工企業(yè))
評(píng)論
0/150
提交評(píng)論