




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、上海大學(xué) 2011 2012 學(xué)年 冬 季學(xué)期試卷A課程名: 面向?qū)ο蟪绦蛟O(shè)計A 課程號:09366046學(xué)分: 5 一選擇 (18分, 其中 1-7每小題2分, 8-11每小題1分) 1. (多選)C+語言編程的優(yōu)勢是 A是一種面向?qū)ο蟮恼Z言,而生成的代碼運(yùn)行時開銷小。B是一種面向過程的語言,用自頂向下設(shè)計方法進(jìn)行設(shè)計。C易學(xué)易用,比用VB,Delphi,java語言編程容易些。D是強(qiáng)大的專業(yè)級的編程語言,最適合開發(fā)系統(tǒng)級軟件。 2. 以下表述錯誤的是:A. 面向?qū)ο蟮某绦蛟O(shè)計工作包括通用算法、類、消息、類之間關(guān)聯(lián)、組件等設(shè)計。BC+語言中類和對象是完全相同的概念。C封裝
2、意味著對象內(nèi)部是如何工作的對客戶端來說是不可見的。D多態(tài)性成員函數(shù)意味著其虛函數(shù)調(diào)用的入口地址是運(yùn)行期綁定。E. 面向?qū)ο蟮木幊蹋獔?zhí)行一個任務(wù)有兩種方式:客戶/服務(wù)器模式和委托/事件模式。F. Windows編程是一種事件機(jī)制的編程。 3. 名空間的用途是A.防止標(biāo)識符沖突,提供標(biāo)識符的組織方式B.表達(dá)標(biāo)識符間的繼承關(guān)系 C.表示變量 4. (多選)要設(shè)計一個汽車制造調(diào)度系統(tǒng),好的做法是:A構(gòu)建Name類, Automobile類,BuildEngine類,Machine類,Work類。B構(gòu)建Automobile類,Engine類,PaintMachine類,Machin
3、e類,Worker類。CAutomobile類含有Engine類型的成員變量。DMachine類作為PaintMachine類的基類。EWorker類作為Name類的派生類。5. (多選)以下代碼錯誤的是:A. void func( int &c);B. int a; int &c=a; C. int &func();D. int a; int &c; E. virtual void h(); 6. (多選) 已有以下定義, 為派生類CD定義構(gòu)造函數(shù),正確的實(shí)現(xiàn)代碼是:class CB .public:CB();CB( string );CB( con
4、st Base&);protected:string _name;class CD: public CB . ;A. CD:CD() CB(); BCD: CD( string s):CB(s)C. CD: CD() D. CD: CD(const CB& b):CB(b) 7. (多選)有以下定義,結(jié)果為true的表達(dá)式是class CB virtual void m(); class CD : public CB ; CB *pb=new CD; CD *pd=(CD*) pb;A.typeid( pb) = typeid (pd)B. typeid( pb) =
5、 typeid (CB *)C.typeid( pb) = typeid (CD *)D. typeid( *pb) = typeid (CB) E.typeid( *pd) = typeid (CD )F. typeid( pd) = typeid (CB *) 8. 重載操作符>>從輸入流中讀取數(shù)據(jù)到CMy類型的對象中正確的設(shè)計是:A. istream & operator>>( istream &in, CMy & obj);B. istream & operator>>( istream in, CMy ob
6、j); Cistream & operator>>( istream& in, CMy obj); Distream operator>>( istream in, CMy obj); 9. 從鍵盤輸入數(shù)據(jù)到變量x,應(yīng)用標(biāo)準(zhǔn)C+庫編程,正確的是:A. cout>>x ; B. std:cin<<x:C. std:cin>>x;D. using namespace std; cin<<x; 10. 設(shè)計一個函數(shù),功能是使調(diào)用者的兩整型變量數(shù)據(jù)交換,其函數(shù)原型應(yīng)該是:A. void swap
7、(int a,int b);B. void swap( &int x,&int y);C. int swap(int a);D. void swap(int &a,int &b); 11. 動態(tài)分配n個整數(shù)的內(nèi)存空間,C+編程方法是:A.int *p=new intn*sizeof(int);B.int a =new intn;C.int *p=new intn;D.int an; 二. 填空 (27分,其中每小題1分) 1. 面向?qū)ο蟪绦蛟O(shè)計語言的主要特征是_2. 函數(shù)參數(shù)的設(shè)計其數(shù)據(jù)傳遞有三種方式,分別是傳_2.1_
8、、傳_2.2_、傳_2.3_3. 修改下面代碼的錯誤第_3.1_行代碼改寫為_3.2_ int & db1( int i )/1 int j = 2*i;/2return j ;/3 4. 設(shè)計一個函數(shù)encode,功能是對字符串加密,你設(shè)計的函數(shù)原型(接口)是:_4.1_其中相關(guān)參數(shù)和返回的說明:_4.2_ 5. 已有定義:class BC public:int b; ;class DC : public BC public: int d; ;BC *pb=new DC;所創(chuàng)建的DC對象有_5.1_個成員變量,現(xiàn)要對其中成員變量d賦值為1,代碼是_5.2_
9、60;6. 設(shè)計一個兩個開關(guān)都能任意控制一個樓道電燈的監(jiān)控器Windows應(yīng)用程序,樣例如下圖界面。完成你的解決方案(注: 可隨意用英文中文表述): 系統(tǒng)采用Visual Studio C+開發(fā)平臺的什么項目類型框架編程_6.1_。 界面顯示的對話框從_6.2_類派生,它包含兩個邏輯開關(guān),一個邏輯電燈,在什么地方初始化它們:_6.3_ 邏輯開關(guān)類,包含那些含義的成員變量怎么關(guān)聯(lián)邏輯電燈: _6.4_, 包含那些含義的成員函數(shù):_6.5_ 邏輯電燈類,怎么關(guān)聯(lián)電燈圖標(biāo):_6.6_包含那些意義的成員函數(shù):_6.7_ 對話框中訂閱什么事件來操作(調(diào)用)邏輯開關(guān)
10、的push函數(shù):_6.8_7. 實(shí)現(xiàn)下面的類class CPersonprotected:string name;public:void setname( string name ) _7.1_ =name;string getname() return name;class CWorker : _7.2_double score;public:_7.3_() /構(gòu)造函數(shù)_7.4_ setname( name ) ; /構(gòu)造函數(shù)_7.5_ /析構(gòu)函數(shù)int compareScore( CWorker &worker) if( this->score < worker.get
11、score () return -1;else if( _7.6_ ) return 1;else return 0;double getscore() return score;void setscore( double score ) this->score=score;改寫getscore成員函數(shù)為外聯(lián)式實(shí)現(xiàn) _7.7_改寫setscore成員函數(shù)為外聯(lián)式實(shí)現(xiàn) _7.8_ 8. 填空使下述代碼顯示D:m#include <iostream.h>class Bpublic:_;class D : public Bpublic:void m( ) cout<
12、<”D:m()”<<endl; ;void main( )D d1; B *p= &d1; p->m();三. 閱讀程序 ( 15分,每小題3分 ) 1. 寫出輸出結(jié)果:_ class Containerenum MaxSize = 5 ;int array MaxSize ;int n;public:Container() n=0;void append( int a)if( n < MaxSize )array n =a;n+;elsethrow "越界" 2. 寫出輸出結(jié)果:_ #include<iost
13、ream> #include<string> #include<sstream> using namespace std;int main(int argc, char * argv)string str="李偉 10 2000.00"istringstream istm( str ); string name; int age; double salary;istm>>name>>age>>salary;double r=10;salary +=age*r; ostringstream ostm;ostm
14、<<"姓名"<<name<<" 工齡"<<age<<" 新工資"<<salary;cout<< ostm.str()<<endl; return 0;3. 下面的程序,用標(biāo)號共標(biāo)記了6個斷點(diǎn),寫出程序先后運(yùn)行到斷點(diǎn)的標(biāo)號序列(寫法舉例:1,3,3)4, _3.1_ 輸入數(shù)據(jù)100 200的運(yùn)行結(jié)果: _3.2_ class IEventHandlepublic:virtual void OnMouseDown(int x,int
15、 y)=0; /1;class CRecv : public IEventHandle public:virtual void OnMouseDown(int x,int y)cout<<"x="<<x<<" "<<"y="<<y<<endl;/2; class Mouseint x; int y;IEventHandle * pSink;public:Mouse( int x,int y, IEventHandle * pSink) this->
16、x=x; this->y=y; this->sink=sink; /3 void fireEvent()pSink-> OnMouseDown(x, y); void main( ) CRecv recv;/4int a,b; cin>>a>>b; /5Mouse mouse( a,b,& recv);mouse. fireEvent(); 4.學(xué)生數(shù)據(jù)庫查詢打印程序,寫出輸出結(jié)果:_ 數(shù)據(jù)文件DBData.txt中有數(shù)據(jù)如下:Student 020001 張三Student 010002 李四Score 數(shù)學(xué) 020001
17、 80Score 數(shù)學(xué) 010002 70Score 物理 010002 60Score 政治 020001 90 int main()CApp app;app.ReadDatabase("DBData.txt");app.Report(); return 0; class CStudentmap<string,int> courseScores; public:string m_name;string m_ID;CStudent() CStudent(string id,string name)m_ID=id; m_name=name;vo
18、id setCourseScore(string courseName,int score)courseScorescourseName=score;void printScore() for(map<string,int>:iterator p=courseScores.begin();p!=courseScores.end(); p+)cout<<p->first<<"t"<<p->second<<endl; ;class CAppdeque<CStudent> m_stus;CStud
19、ent * findStudent( string id )for( int i=0;i<m_stus.size();i+ )CStudent &stu = m_stusi;if( stu.m_ID = id )return &stu;return NULL;public:void ReadDatabase(const char* filename);void Report(); void CApp :Report() cout<<"t成績表"<<endl;deque<CStudent>:ite
20、rator it;for( it=m_stus.begin();it!=m_stus.end();it+)CStudent& stu=*it;cout<<stu.m_ID<<" "<<stu.m_name<<endl;stu.printScore();void CApp :ReadDatabase(const char* filename) ifstream ifile(filename);while(ifile) string type;ifile>>type;if(type="Student&
21、quot;)string id, name;ifile>>id>>name;CStudent stu(id,name);m_stus.push_back(stu);else if(type="Score")string id,courseName;int score;ifile>>courseName>>id>>score;CStudent *pStu = findStudent(id) ;if( pStu !=NULL )pStu->setCourseScore( courseName, score);四.
22、 改錯(對有標(biāo)號的行,有錯標(biāo)記X,無錯標(biāo)記)( 20分,每小題0.5分 )class Apublic:virtual void v(int x) = 0;/1 /2 class B : A /3 int x;static int s; const int c; protect:/4void protectedFunc( int a) x=s*a; /5public:B( ): c(0),x(0) /6 B(int a) x=a; c=0;/7B( ) /8 void publicFunc(int a) this -> protectedFunc (a); /9int & getX
23、( ) return &x; /10 void sameNameFunc( int a) cout<<a; /11 static void staticSetS( int a) s=x; /12int getS()return this->s; /13virtual void v(int a) cout<< "B"<<a; /14;int B:s =0; /15 void g(B *pB) void D: publicDFunc( ) /21B:publicFunc(0); /22 protectedF
24、unc(1);/23 class D : public B /16int *p;public:int d;D( ):p=NULL /17DC(int a) BC( a ); p=NULL; / 18 virtual D( ) /19virtual void v(int a) cout<< "D"<<a;void sameNameFunc(const char * s) cout<<s; void set(int *p)x=*p; /20void publicDFunc();int main( ) A obj=new A;/24D dc;d
25、c. sameNameFunc (10);/25dc. sameNameFunc ("abc"); /26int &x=dc.getX( ); /27 B bc; /28tectedFunc(1);/29 A *pa=new D(2); /30pa.v(1); /31 delete pa; /32 D *pdc= <D *>dc;/33 B *pb=&dc; /34 B:staticSetS (2);/35 D *pdc= dynamic_cast<D*>(pb);/36pdc=(D*)pb;/37pdc->v(in
26、t a);/38pdc->d = 1;/39g(&dc);/40 五程序設(shè)計 ( 20分,每小題10分 1. 設(shè)計一個模板函數(shù),在數(shù)組中查找數(shù)據(jù),并編寫main函數(shù)測試它。 其模板函數(shù)函數(shù)名SeqSearch 2. 使用C+標(biāo)準(zhǔn)庫,采用面向?qū)ο蟮姆椒ㄔO(shè)計一個程序,讀證券交易行情文件,輸出一個按收盤價由小到大排序的的報表數(shù)據(jù)文件stock.txt格式如下代碼 開盤價 收盤價 成交量數(shù)據(jù)文件樣例:600028 3.003.10 2900000600171 10.109.5023000600900 6.00 6.20 300000000825
27、4.104.025000 輸出結(jié)果樣例:6000283.003.1029000000008254.104.0025000600171 10.109.5023000600028 3.00 3.102900000 -完- 上海大學(xué) 2011 2012 學(xué)年 冬 季學(xué)期答卷 小題第 一 題 選擇題 18% 1-7每小題2分, 8-11每小題1分1 AD 2B 3A 4BCD 5DE 6BCD 7BE 8A 9C 10D 11C
28、0;小計: 小題第二題 填空題 27% 每小題1分1封裝,繼承,多態(tài) 2.1值 2.2地址 2.3引用 小題第 二 題 填空題 3.1 2 3.2static int j = 2*i; 或 int &j = *new int; 4.1 void encode(char *sEnText,const char *sText,const char *sKey ); 4.2 sEnText:加密后的文本,sTex:待加密的文本,sKey:密鑰,返回空 5.1 2
29、60;5.2 DC *pdc=(DC*)pb; pdc->d = 1; 或 DC *pdc=static_cast<DC*>(pb); pdc->d = 1; 6.1 MFC 應(yīng)用 (注:只要含MFC給分) 6.2CDialog 6.3OnInitDialog 或 對話框初始化的地方 6.4亮熄狀態(tài)、邏輯燈對象的指針 6.5Push (或:按動操作函數(shù)) 6.6包含一個成員變量指向類型CStatic對象圖標(biāo)(電燈) 6.7setOnOff(或設(shè)置亮熄狀態(tài)的函數(shù)) 6.8WM_MOUSED
30、OWN 或 鼠標(biāo)按下消息) 7.1this->name 7.2public CPerson 7.3CWorker() 7.4CWorker(string name) 7.5CWorker() 7.6this->score > 7.7double CPerson:getscore() return score; ( 或 return this->score; ) 7.8void CPerson:setscore( double score ) this->score=score;
31、60;8virtual void m( )=0; 或 virtual void m( )cout<<”B”; 小計 小題第 三 題 閱讀題 12% 每小題3分101234越界 2姓名 李偉 工齡 10 新工資 2100.00 3.14,5,3,2 3.2x=100 y=200 4成績表020001 張三 數(shù)學(xué) 80 政治 90010002 李四數(shù)學(xué) 70物理 60 小計 第 四 題 改錯題 20%每小題0.5分小題 小題 小題 小題 小題
32、60;12×3×4X567×8910X1112×1314151617X18×1920X21222324×25×26272829X3031X3233X3435363738X3940小計: 五程序設(shè)計 20% 1. (10%) 設(shè)計一個模板函數(shù),在數(shù)組中查找數(shù)據(jù),并編寫main函數(shù)測試它。 其模板函數(shù)函數(shù)名SeqSearch template<class T>int SeqSearch( T list , T key,int n)for(int i=0;i<n;i+)
33、if(listi=key)return i;return -1;int main()int a5= 43,66,2,1,33;int x;cin >> x;int index = SeqSearch( a, x,5);if( index >= 0 )cout<<index;elsecout<<"不存在" return 0;2. 使用C+標(biāo)準(zhǔn)庫,采用面向?qū)ο蟮姆椒ㄔO(shè)計一個程序,讀證券交易行情文件,輸出一個按收盤價由小到大排序的的報表#include<iostream> #include <fstream> #include <string>#include <deque> #include <algorithm>using namespace std;class Sto
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度景觀園林裝修承包合同安全責(zé)任承諾
- 二零二五年度展覽中心大廳臨時展覽租賃協(xié)議及展覽設(shè)計服務(wù)協(xié)議
- 2025年度物業(yè)公司物業(yè)服務(wù)創(chuàng)新項目合作協(xié)議
- 二零二五年度陽光房景觀設(shè)計施工合同
- 2025年度智慧城市建設(shè)異業(yè)合作實(shí)施方案
- 二零二五年度文化創(chuàng)意產(chǎn)業(yè)過橋墊資協(xié)議
- 二零二五年度研發(fā)中心員工借調(diào)與技術(shù)交流協(xié)議
- 2025年度智慧城市建設(shè)項目股東投資合伙協(xié)議書
- 二零二五年度合伙企業(yè)合伙人退伙補(bǔ)償協(xié)議
- 二零二五年度農(nóng)村土地承包經(jīng)營權(quán)租賃與農(nóng)村旅游基礎(chǔ)設(shè)施建設(shè)合同
- 胸痹心痛中醫(yī)診療方案及臨床路徑
- 泛讀2unit2-music
- 中學(xué)生防溺水安全教育課件(PPT 44頁)
- ISO-IEC17025-2017實(shí)驗室管理體系全套程序文件
- 2019版外研社高中英語選擇性必修二Unit 1 Growing up 單詞表
- 重慶危險性較大的分部分項工程安全管理實(shí)施細(xì)則
- 三菱 PLC FX2N-4AD 4DA 模擬量模塊教材(課堂PPT)
- 有機(jī)金屬化學(xué)1
- JIT標(biāo)準(zhǔn)作業(yè)作業(yè)指導(dǎo)書
- 安徽省2020-2021學(xué)年七年級語文下學(xué)期期末測試卷[含答案]
- 混凝土面板堆石壩接縫止水
評論
0/150
提交評論