




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
試題紙(A卷)課程名稱:程序設計基礎(二) 考生姓名一、單項選擇題(每題2分,共20分 下面關 的描述中,錯誤的是 ) 該類的私有成 類中的成員都是這個類 關系可以繼類A定義了私有函數(shù)F1,B和C為A的派生類,分別為保護繼承和公有繼承。 )可 A.A的對 B.B類 C.A類 D.C類基類 ,但允許派生類成 ,這樣既有一定隱藏能力,又提供了開放的接口 構造函 B.虛函 C.析構函 函 te<classT>Tfunc(Tx,Ty){return classAA intpublic:intgetRef() {return&a; intgetValue()const{returna; voidset(intn)const{a=n; friendvoidshow(AAaa)const{cout<<a; A.只能重載C++中已經有的運算符,不能定義新運算符C.可以對基本類型(int) 行初始 >: 二、程序改錯題(共20分void AAal(1);constAAa2(2); al.print(3); usingnamespacestd;classTest staticintval;inta;public:staticintvoidsfunc(TestintintTest::func(){ returnval++; voidTest::sfunc(Test&r) }voidmain( cout<<"Result1="<<Test::func()<<endl;Testa;
usingnamespacestd;classAvoidFuncA(){ virtualvoidFuncB(){cout<<"B";}classB:publicvoidFuncA(){A::FuncA();cout<<"AB";}virtualvoidFuncB(){cout<<"BB"; void Bb; A*pa=&b; A*pa2=newA; deletepa2;}}usingnamespacestd;intDiv(intx,int{if(y==0)throwy;elsereturnx/y;}voidmain( } cout<<"除數(shù)為 }
usingnamespacestd; te<classT>Tmax(Tx,T{cout<<"[T]"; returnx>y?x:y; intmax(intx,inty){cout<<"[int]"; returnx>y?x:y;}voidmain(){inta(20),b(9); doublem=11.2,n=9.5;}四、填空題(請將程序按要求補充完整,每空2分,共20分rectangle'sareais6.3#include<iostream>#include<cstring>usingnamespacestd;classTwoDShape charpublic:TwoDShape(char ;char*getName(){returnname;
#include<iostream>usingnamespacestd;classDate Date(intm=1,inty=0) {}voidPrint() operator+( classRec:public doublewidth,public:Rec(doublew,double {width=w; height=h;}doublearea(){ ;}void shape=newcout<<shape->getName()<<"'sareais";delete}private:intDateoperator+(Date&d1, return}void{Date }五、編程題(每小題10分,共20分某學校對教師月工資的計算為固定工資補貼教授的固定工資為 元每補貼50元;的固定工資為3000元,每補貼30元;講師的固定工資為2000元,每補貼20元。定義教師抽象類Teacher,成員數(shù)據包含,工號,,成員函數(shù)包括構造函數(shù)(至少需要和工號,設置SetHour和計算工資函數(shù)pay。由Teacher類派生不同的教師(教授Professor類Associate_Professor類講師Lecturer類,Pay(用來計算該教師的月工資。(imagComplex類的如下,請實現(xiàn)該類class doublereal,imag;Complex(doublere=0,double plex(doublere,doubleimdoubleGetReal();//返回復數(shù)的實部doubleGetImag();Complexoperator+(Complex&c);//復數(shù)加法Complexoperator(Complex&c);//復數(shù)減法Complexoperator*(Complex&c);Complexoperator/(Complex&c); //復數(shù)除法,如果c==0,則退出程序booloperator==(Complex&c); friendostream&operator<<(ostream plex&c);參考答案一、單項選擇題(每題2分,共20分ADCCB二、程序改錯題(共20分(1)5,protected改為6,Point(intxx,intyy)Point(intxx=0,int7,const11Point(intxx=0,intyy=1)Point(intxx,int第14行,end改 (1)第3行 te<classT,intN>改 te<classT,int7,Tget(Tpos)Tget(int10,Vector::set改為第12行,增加內 te<classT,int13,Vectorv改為Vector<T,N>三、閱讀程序寫結果(每小題4分,共20分12四、填空題(請將程序按要求補充完整,每空2分,共20分(2)virtualdoublearea()(4)returnwidth*heightfriendintyear,month五、編程題(每小題10分,共20分class 4{charname[10];intId;inthour;Teacher(char*pname,intid,inth=0);voidSethour(inth);intclassProfessor:public 2{Professor(char*pname,intid,inth);intPay();classAssociate_Professor:public 2{Associate_Professor(char*pname,intid,inth);intPay();classLecturer:public 2{Lecturer(char*pname,intid,inth);intPay();Teacher::Teacher(char*pname,intid,int{}voidTeacher::Sethour(int Professor::Professor(char*pname,intid,int double returnAssociate_Professor::Associate_Professor(char*pname,intid,int double returnLecturer::Lecturer(char*pname,intid,int double return2000+20*hour;plex(doublere,double 1 plex(doublere,double 1 double 1 return double 1 return ComplexComplex::operator+(Complex 1 return ComplexComplex::operator-(Complex //復數(shù)減 1 returnComplex(real-c.real,imag- ComplexComplex::operator*(Complex 1 returnComplex(real*c.real- ComplexComplex::operator/(Complex 1 if(c.real==0&&c.imag==0)exit(0);doublea=real*c.real+imag*c.imag;doubleb=i
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 公益類項目合同范本
- 雙方解聘合同范本
- 烹飪原料知識練習題庫及答案
- 南沙初中食堂承包合同范本
- 臺灣履行合同范本
- 農村包清工合同范本
- 七年級組工作計劃
- 七年級政治教學工作總結
- 單位招標合同范本
- 單間轉租合租合同范本
- 高校電子課件:現(xiàn)代管理學基礎(第三版)
- 小企業(yè)會計實務全書ppt完整版課件整本書電子教案最全教學教程
- (完整word版)服務質量評價表
- 腸瘺治療PPT醫(yī)學課件(PPT 25頁)
- 員工轉正評價表
- 道路交通事故責任認定行政復議申請書范例
- 鄭州大學圖書館平立剖面效果圖
- 高效液相含量測定計算公式
- 公安機關通用告知書模板
- 《小學數(shù)學課程與教學》教學大綱
- 《手機攝影》全套課件(完整版)
評論
0/150
提交評論