![程序設(shè)計(jì)語言a2010期中試卷參_第1頁](http://file4.renrendoc.com/view/7a1f211a8237b1daaa1da42b61aa06de/7a1f211a8237b1daaa1da42b61aa06de1.gif)
![程序設(shè)計(jì)語言a2010期中試卷參_第2頁](http://file4.renrendoc.com/view/7a1f211a8237b1daaa1da42b61aa06de/7a1f211a8237b1daaa1da42b61aa06de2.gif)
![程序設(shè)計(jì)語言a2010期中試卷參_第3頁](http://file4.renrendoc.com/view/7a1f211a8237b1daaa1da42b61aa06de/7a1f211a8237b1daaa1da42b61aa06de3.gif)
![程序設(shè)計(jì)語言a2010期中試卷參_第4頁](http://file4.renrendoc.com/view/7a1f211a8237b1daaa1da42b61aa06de/7a1f211a8237b1daaa1da42b61aa06de4.gif)
![程序設(shè)計(jì)語言a2010期中試卷參_第5頁](http://file4.renrendoc.com/view/7a1f211a8237b1daaa1da42b61aa06de/7a1f211a8237b1daaa1da42b61aa06de5.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
上海交 大 試卷(A)參考答(2009至2010學(xué)年第_二_學(xué)期期中考班級(jí) 學(xué) 課程名稱 成績(jī) 一.填空題(每題1分,共10分C++源文件名的后綴是 編寫C++語言源程序并上機(jī)運(yùn)行的一般過程為編輯、編譯、和執(zhí)行。其中,編輯的件,的作用是將此目標(biāo)文件與被調(diào)用到的其他目標(biāo)文件在一起。如果A是已經(jīng)定義好的一個(gè)類,r2是A類的一個(gè)對(duì)象,p是指向A類對(duì)象的指針。執(zhí)pnewA(r2)時(shí),系統(tǒng)會(huì)自動(dòng)調(diào)用拷貝構(gòu)造函數(shù),執(zhí)行deletep系統(tǒng)會(huì)自動(dòng)調(diào)用析構(gòu)函數(shù)。5。類的私有成員只能通過它的成員函數(shù)以及來。無論哪種派生方法,基類中的私有成員既不許外部函數(shù),也不許派生類中的成員函數(shù)。6。公有繼承時(shí),基類的保護(hù)成員在派生類中是保護(hù)成員成員,基類中的公有成員在派生類中是公有成員成員。承諾人 二.看程序,寫結(jié)果(每題5分,共30分)1.寫出下列程序執(zhí)行結(jié)果【構(gòu)造函數(shù)和析構(gòu)函數(shù)的順序】 Point{ x,Point(inta=1,intb={x=a;y=cout<<"Point("<<x<<","<<y<<")"<<}~Point(){cout<<"Point["<<x<<","<<y<<"]"<<endl; Point { origin,*pp=newPoint(3,{Pointpoint1(-5,}Pointpoint2(1,2);deletepp;return}class{friendostream&operator<<(ostream&os,constCST&ob);CST(intv1=0){data=v1;++count;cout<<“constructing“<<data<<~CST(){ count--;cout<<“deconstructing“<<data<<endl;}operatorint()const{returndata;}staticintcount;intostream&operator<<(ostream&os,constCST&ob{os<<"data="<<os<<“,count=”<<ob.count<<endl;returnos;}ConstructingCST::count=ConstructingCST::count=Constructingdata=4,count=deconstructingCST::count=1Constructing10deconstructing10data=10,count=1deconstructingint{CSTcs,intcout<<"CST::count="<<CST::count<<ptr1=newcout<<deletecout<<"CST::count="<<CST::count<<ptr2=*ptr2=cout<<value=cout<<value<<return}}class{intx,y;coord(inti=0,intj=0){x=i;y=j;voidprint(){cout<<"x:"<<x<<",y:"<<y<<endl;}coordoperator++(){++x;return*this;}coordoperator++(intn){coordtmp=*this;++y;returnx:x:5,y:x:5,y:x:5,y:int{coord(ob++).print();print2(x=5,y=10ob.print();operator++(intny1,xx=5,y=11return}classcomplexintreal;//intimag;//complex(intr=0,inti=0){real=r;imag=complex(constcomplex&t){real=t.real+2;imag=t.imag+1;}voidshow(){cout<<real<<"+"<<imag<<"I";}};void{complex c2=cout<<c1= 賦值運(yùn)算,調(diào)用的是默認(rèn)的賦值函數(shù),c2的成員變量值賦給c1。寫出下列程序的執(zhí)行結(jié)果classC_AC_A(charvalue=‘@’){data cout<<"Object"<<data<<"constructor" C_A(constC_A&obj){ obj.data+cout<<"Object"<<data<<"constructor"{cout<<"Object"<<data<<"destructor"<<endl;} ObjectaconstructorObject8constructorObject9constructorObjectmconstructorObjectmdestructorObject8destructorObjectbconstructorObjectObjectaconstructorObject8constructorObject9constructorObjectmconstructorObjectmdestructorObject8destructorObjectbconstructorObjectmconstructorObjectmdestructorObjectbdestructorObjectadestructorObject9destructor staticC_Af // Objectbconstructorintmain(){C_Areturn}classCBaseCBase(int{m_data=cout<<"ConstructorofCBase.m_data="<<m_data}virtual~CBase(){cout<<"DestructorofCBase.m_data="<<m_data<<endl;}virtualvoidprint(){cout<<"CBase::m_data="<<m_data<<endl;}intclassCDerived:public{CDerived(int
{cout<<"ConstructorofCDerived."<<endl;)~CDerived(){cout<<"DestructorofCDerived."voidprint(){cout<<"CDerived::m_data="<<m_data<<endl;}intint{CBase*p=newCDerived(67),baseObj=p-ConstructorofCBase.m_data=63ConstructorofCDerived.deletereturn}DestructorofDestructorofCBase.DestructorofCBase.二.程序填空(每空2分,共30分classA{ operator==(constA&a1constA&a2)//判兩數(shù)據(jù)成員指向的對(duì)象相{return *(a1.a)==*(a2.a) ;}A(intaa0a newint(aa) //aa初始化aA A&obj a=new *a= } delete }//釋放動(dòng)態(tài)空int*在如下Rational類的基礎(chǔ)上又定義了一個(gè)Complex類。復(fù)數(shù)類具有輸入輸出和加能。classRationalfriendistream&operator>>(istream&in,Rational&obj);//friendostream&operator<<(ostream&os,constRational&obj);//輸出重載函數(shù)friendRationaloperator+(constRational&r1,constRational&r2運(yùn)算符重載friendRationaloperator*(constRational&r1,constRational&r2);//*運(yùn)算符重載intnum;intden;void Rational(intn0,intd1)numn;dend;ReductFraction();}operatordouble //double型{ (double(num)/den);classfriendComplexoperator+(constComplex&x,constComplex&y);friendistream&operator>>(istream&is, Complex&obj friendostream&operator<<(ostream&os,constComplex&obj);Rationalreal; Rational Complex(intr1=0,intr2=1,inti1=0,inti2= real(r0,r1),imag(i1, Complexoperator+(constComplex&x,constComplex{Complextmp.real=x.real+ tmp.imag=x.imag+y.imag }三。編程(每題10分,共30分int //輸出:10 //輸出:21 //輸出:為1號(hào)服務(wù) //輸出:30 //3return} 4構(gòu)造函 2Come函 2Go函 2classintco{covoid{co}void{if(com-goNum==0) } void{Aa1(3,15),a2(2,5),a3,a3=a1+a2;a4=a1-a2;cout<<a3;cout<<a4}
溫馨提示
- 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. 人人文庫(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池塘清淤工程的施工合同
- 9 知法守法 依法維權(quán) 依法維權(quán)有途徑(說課稿)-部編版道德與法治六年級(jí)上冊(cè)
- 21 淡水資源 說課稿-2024-2025學(xué)年科學(xué)三年級(jí)上冊(cè)青島版
- 2025法律法規(guī)工傷員工續(xù)簽合同問題 管理資料
- 6將相和(第一課時(shí))說課稿-2024-2025學(xué)年五年級(jí)上冊(cè)語文統(tǒng)編版
- 農(nóng)村荒山承包合同范本
- 2023二年級(jí)數(shù)學(xué)下冊(cè) 四 認(rèn)識(shí)萬以內(nèi)的數(shù)第8課時(shí) 近似數(shù)說課稿 蘇教版001
- Unit 1 Making friends PartA Let's talk(說課稿)-2024-2025學(xué)年人教PEP版(2024)英語三年級(jí)上冊(cè)
- 2023二年級(jí)數(shù)學(xué)下冊(cè) 四 認(rèn)識(shí)圖形(七巧板)說課稿 西師大版
- 《8 花卉栽培》(說課稿)-2023-2024學(xué)年六年級(jí)上冊(cè)綜合實(shí)踐活動(dòng)皖教版
- 改革開放前后家鄉(xiāng)的變化教學(xué)課件
- 一年級(jí)的成長(zhǎng)歷程
- 2024年南京鐵道職業(yè)技術(shù)學(xué)院高職單招(英語/數(shù)學(xué)/語文)筆試歷年參考題庫(kù)含答案解析
- 正月十五元宵節(jié)介紹課件
- 病毒性肺炎疾病演示課件
- 中考英語語法填空專項(xiàng)練習(xí)附答案(已排版-可直接打印)
- 口腔醫(yī)學(xué)中的人工智能應(yīng)用培訓(xùn)課件
- 軟星酒店網(wǎng)絡(luò)規(guī)劃與設(shè)計(jì)
- 自然辯證法概論(新)課件
- 基層醫(yī)療機(jī)構(gòu)基本情況調(diào)查報(bào)告
- 六西格瑪(6Sigma)詳解及實(shí)際案例分析
評(píng)論
0/150
提交評(píng)論