上海大學(xué)C++2014-2015秋A---答案--t_第1頁(yè)
上海大學(xué)C++2014-2015秋A---答案--t_第2頁(yè)
上海大學(xué)C++2014-2015秋A---答案--t_第3頁(yè)
上海大學(xué)C++2014-2015秋A---答案--t_第4頁(yè)
上海大學(xué)C++2014-2015秋A---答案--t_第5頁(yè)
已閱讀5頁(yè),還剩4頁(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、精選優(yōu)質(zhì)文檔-傾情為你奉上精選優(yōu)質(zhì)文檔-傾情為你奉上專心-專注-專業(yè)專心-專注-專業(yè)精選優(yōu)質(zhì)文檔-傾情為你奉上專心-專注-專業(yè)序號(hào)試卷 第 1 頁(yè) ( 共 5 頁(yè) )4 GetData函數(shù)功能是Get它動(dòng)態(tài)創(chuàng)建的包含有數(shù)據(jù)的基地址,及數(shù)據(jù)個(gè)數(shù),好的設(shè)計(jì)方案及客戶對(duì)它的正確調(diào)用是:A int GetData( int * pp ); int *pd; int n = GetData( pd );B int * GetData( int n ); int n=3; int *pd = GetData( n );C int GetData( int pp ); int *pd; int n = Ge

2、tData( pd );Dint GetData( int * pp ); int *pd; int n = GetData(&pd );5. 已有定義class K private:K();修改錯(cuò)誤:A去掉private: B. K k1; 改為 K k1();Cprivate 改為publicD. ; 改為 6 (多選)設(shè)計(jì)一個(gè)影片管理系統(tǒng),包括一般影片、外國(guó)片,影片剪接,現(xiàn)有一部外國(guó)影片Titanic (泰坦尼克號(hào)),如下的解決方案正確的有:AFilm作為基類(lèi),F(xiàn)oreignFilm和 DirectorCut作為Film的派生類(lèi)。BTitanic作為Film的的成員變量。CTitanic

3、是ForeignFilm的一個(gè)實(shí)例。 DFilm作為類(lèi)ForeignFilm和類(lèi)DirectorCut的成員變量。E數(shù)據(jù)輸出Output函數(shù)采用虛成員函數(shù),F(xiàn)ilm、ForeignFilm、DirectorCut都實(shí)現(xiàn)它。7. 已有定義:class BC public:int b; void mfunc()coutBC; ;class DC : public BC public: int d; void mfunc() BC:mfunc();coutd = 1;C. DC *p=pb;p.d = 1;D. DC *pdc=static_cast(pb); pdc-d = 1;8 重載右移操作符

4、,從流輸入數(shù)據(jù)到復(fù)數(shù)類(lèi)對(duì)象,設(shè)計(jì)方案選擇:Aistream & operator( istream &istm, Complex &c);Bistream & operator( istream istm, Complex c); Cistream & operator( istream& istm, Complex c); Distream operator( istream istm, const Complex & c);EComplex operatorname=name; /構(gòu)造函數(shù)_8.5_ /析構(gòu)函數(shù)static int compareScore( Student &stu1,

5、Student &stu2) if( stu1.getscore () score=score;改寫(xiě)getname成員函數(shù)為外聯(lián)式實(shí)現(xiàn)_8.7_改寫(xiě)setscore成員函數(shù)為外聯(lián)式實(shí)現(xiàn)_8.8_ 二填空(26分,1,7題每題3分,其他每空1分)1.面向?qū)ο蟪绦蛟O(shè)計(jì)語(yǔ)言的主要特征是_2. 返回對(duì)象的引用,修改下面代碼int& dl( int n ) _ int j= 2*n;return j; 3. 下面代碼CA和CB類(lèi)型的對(duì)象分別有_3.1_個(gè)數(shù)據(jù)成員,實(shí)現(xiàn)類(lèi)的構(gòu)造函數(shù),初始化數(shù)據(jù)成員class CAprivate:int a;public:CA(int a) _3.2_ ;4. 設(shè)計(jì)一個(gè)函數(shù)

6、decode,功能是對(duì)字符串,用密鑰解碼,設(shè)計(jì)函數(shù)原型(接口)是:_4.1_其中相關(guān)參數(shù)和返回的說(shuō)明:_4.2_5. 異常處理代碼填空int div( int a,int b)if(b =0 )_5.1_“error:b=0”;return a/b;class CB : public CAint b;public:CB(int a,int b) _3.3_ _3.4_;int main( )tryint u,v; cinuv;coutu/v=div(u,v);_5.2_couteendl;return 0;試卷 第 3 頁(yè) ( 共 5 頁(yè) )2. 下面代碼的輸出結(jié)果_ class B publ

7、ic:B() coutB; virtual B()coutB; void main() B* p =new Z; delete p ; 3. 下面的程序?qū)懭氲絛ata.txt文件中的內(nèi)容_3.1_屏幕顯示的輸出的內(nèi)容_3.2_#include #include using namespace std;int main( )ostringstream ostm;string name=wang; int age=20;ostm 姓名 name 年齡 ageendl; ofstream ofile( data.txt );ofilestr1namestr2age ) cout 姓名 name 去年

8、 age 今年 age - 2endl;ifile.close();return 0;int main( )vector students;for(int i=0;iname score;CStudent stu(name);stu. setscore(score);students.push_back(stu);assert(students.size() 0 );cout”與” students0. getname() ”分?jǐn)?shù)相同的學(xué)生有:”endl;for( int i=1; i students.size() ;i+ ) int comp=_8.10_;if( comp=0) /i學(xué)生

9、如果與0學(xué)生分?jǐn)?shù)相同cout studentsi. getname()endl;return 0;三. 閱讀程序 (18分,每小題2分)1寫(xiě)出輸出結(jié)果: _class B protected: virtual void f( ) cout”B”endl; public:void g( ) f( ); ;void main( ) D d;d.g( ); class Z: public B public:Z() coutZ ; virtual Z() coutZ ;class D : public Bprotected: virtual void f( ) cout”D”endl;試卷 第 4 頁(yè)

10、 ( 共 5 頁(yè) )class IReportHandlepublic:virtual void handleReport( string r ) = 0; ;class DevServiceClassvector m_RCBs;string m_r;void dchgReport() /數(shù)據(jù)已變化,報(bào)告訂閱者for( auto it = m_RCBs.begin();it !=m_RCBs.end();it+) IReportHandle * p = *it;p-handleReport( m_r );public: void hookReport( IReportHandle *p) /訂

11、閱報(bào)告 m_RCBs.push_back(p); void update(string r) /更新數(shù)據(jù) m_r = r; dchgReport(); ;class DevClientClass : public IReportHandlestring m_name;public:DevClientClass() m_name = DevClient; virtual void handleReport( string r ) /處理數(shù)據(jù)coutm_name handleReport:rendl; ;4. 下面代碼的輸出結(jié)果_class Apublic: void m(const char *

12、str)cout”A”strendl;class Z : public Apublic: void m()coutZendl;int main()Z z1;z1.m();z1.A:m(“a”);return 0;5 下面是設(shè)備監(jiān)控系統(tǒng)采用事件驅(qū)動(dòng)機(jī)制編寫(xiě)的一個(gè)簡(jiǎn)單示例程序,列出程序先后運(yùn)行到斷點(diǎn)位置(已用標(biāo)號(hào)標(biāo)記)的序號(hào),或顯示結(jié)果鍵盤(pán)輸入數(shù)據(jù)前,程序依次運(yùn)行到的斷點(diǎn)序列號(hào)_5.1_從鍵盤(pán)輸入 MMXU1.PNV.phsA.cVal.mag.f=100.5A 回車(chē)后的斷點(diǎn)位置: _5.2_斷點(diǎn)位置然后程序依次運(yùn)行到的斷點(diǎn)序列號(hào): 5.3 程序顯示的輸出結(jié)果: 5.4 #include #inc

13、lude #include using namespace std;int _tmain(int argc, _TCHAR* argv) DevServiceClass dev; DevClientClass cli; dev.hookReport( &cli );char str200; cin.getline( str,sizeof(str) ); /采集數(shù)據(jù)dev.update(str); return 0;試卷 第 5 頁(yè) ( 共 5 頁(yè) )五程序設(shè)計(jì) (20分 , 第1題8分,第2題7分,第3題5分)設(shè)計(jì)一個(gè)模板容器類(lèi),功能是元素的壓入和彈出在同一端進(jìn)行,滿足先進(jìn)后出的要求.并編一個(gè)

14、main函數(shù)測(cè)試該模板容器。模板容器類(lèi)接口要求:類(lèi)名:Stack模板參數(shù)表含模板類(lèi)型參數(shù)T, 和實(shí)例類(lèi)型參數(shù)size (表示容器最大容量) 成員函數(shù):push: 壓入元素;pop: 彈出元素empty:容器是否空;full: 容器是否滿main()函數(shù)要求:創(chuàng)建你的模板容器類(lèi)對(duì)象,循環(huán)壓入n個(gè)string字符串,然后彈出顯示。2. 使用MFC設(shè)計(jì)一個(gè)圖形層次類(lèi)要求1)抽象圖形類(lèi) CShape 成員變量 m_x,m_y 成員函數(shù) draw(CDC*), moveTo(x,y), CShape(x,y) CShape (x=0,y= 0) 2) 圓類(lèi) CCircle 成員變量 m_x,m_y,m_

15、r 成員函數(shù) draw(CDC*), moveTo(x,y),setR(r) , CCircle(x,y,r)3) 矩形框類(lèi)CRectBox 成員變量 m_x,m_y, m_x1,m_y1成員函數(shù) draw(CDC*), moveTo(x,y) , CRectBox(x,y, x1,y2)4) 柱狀圖類(lèi) CBarChart成員變量 m_x,m_y, m_x1,m_y1 /邊框m_datas /畫(huà)柱狀圖的int數(shù)據(jù)容器 成員函數(shù) moveTo(x,y), CBarChart(x,y, x1,y2) draw(CDC*) /畫(huà)出邊框,畫(huà)出數(shù)據(jù)的柱狀圖,設(shè)每根柱的寬度=元素個(gè)數(shù)/(m_x1-m_x)

16、addData(int) /添加數(shù)據(jù)到注:MFC 相關(guān)類(lèi)CDC類(lèi)相關(guān)的成員函數(shù)bool Rectangle( int x1, int y1, int x2, int y2 ); /畫(huà)矩形框(左上角,右下角)bool Ellipse( int x1, int y1, int x2, int y2 ); /畫(huà)橢圓(左上角,右下角) 程序不要求考慮畫(huà)筆及其填充色的問(wèn)題。類(lèi)間關(guān)系要使用繼承.3. IEC61850 變電站通信網(wǎng)絡(luò)與系統(tǒng)C+程序設(shè)計(jì)(課外項(xiàng)目代碼)四. 改錯(cuò)(對(duì)有標(biāo)號(hào)的行,有錯(cuò)標(biāo)記X,無(wú)錯(cuò)標(biāo)記)( 20分,每小題0.5分 )class IObjpublic:virtual void vf

17、unc(int x) = 0;/1_ /2 _ class BC : IObj /3 _ int b;static int s;const int c;public:BC( ): c(0) /4_ BC(int x) b=x; c=0; /5_void BC( ) /6 _ int & getRef( ) return this-b; /7_ static void staticFuncSet(int x)this-b = x; /8_ int getC( )return c; /9_ static void staticFuncSetS( int x) s = x; /10_int getS

18、()return this-s; /11_virtual void vfunc(int x) protectedFunc ( x ); /12_void m(int x) vfunc(x); /13_private:void privateFunc(const char * str) coutstrvfunc(1); /34 _BC *pbc= (BC*)pobj;/35_delete pobj; /36_ BC *pb=&dc; /37 _ BC:m(2); /38_ pb-vfunc(1); /39_DC *pdc= dynamic_cast(pb); /40_答卷 第 1 頁(yè) ( 共 3

19、 頁(yè) )成績(jī)題號(hào)第 二 題 填空題(續(xù)) 5.1(1分)throw5.2(1分)catch6(1分)std7(3分)值,地址,引用8.1(1分)this-name=name8.2(1分)public CPerson8.3(1分)CStudent8.4(1分)CStudent(string name)8.5(1分)virtual CStudent()8.6(1分)stu1.getscore () stu2.getscore ()8.7(1分)string CPerson:getname() return name;8.8(1分)void CStudent :setscore( double sc

20、ore ) this-score=score;8.9(1分)CStudent8.10(1分)CStudent:compareScore(students0, studentsi );小計(jì)題號(hào)第 三 題 閱讀題 18分1(2分)D2 (2分)BZZB3.1(2分)姓名 wang年齡 203.2 (2分)姓名 wang 去年20 今年184 (2分)Z A a5.1(2分)7,5, 3,5.2(2分)85.3(2分)4,2,65.4(2分)DevClient handleReport: MMXU1.PNV.phsA.cVal.mag.f=100.5A小計(jì)上海大學(xué) 2014 2015 學(xué)年 秋 季學(xué)

21、期答卷 A課程名: 面向?qū)ο蟪绦蛟O(shè)計(jì)A 課程號(hào):學(xué)分: 4 應(yīng)試人 應(yīng)試人學(xué)號(hào) 應(yīng)試人所在院系 題號(hào)一二三四五六七八九得分題號(hào)第 一 題 選擇題 16分每小題2分1F2A3C4D5C6ACE7D8A小計(jì):題號(hào)第二題 填空題 26 分1(3分)封裝繼承多態(tài)2(1分)static3.1(1分)1,23.2(1分)this-a = a;3.3(1分): CA(a)3.4(1分)this-b= b;4.1(1分)void decode(const char *str, const char *key,char *tex );4.2(1分)不返回,str:待解碼的字符串,key:密鑰,tex:解碼后的文本 注:教師應(yīng)使用計(jì)算機(jī)處理試題的文字、公式、圖表等;學(xué)

溫馨提示

  • 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)論