版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、上海大學(xué) 2005-2006年冬季學(xué)期試卷成績(jī)課程名:面向?qū)ο蟪绦蛟O(shè)計(jì)C+ 學(xué)分: 5 學(xué)號(hào): 姓名: 院系: 一 選擇1 C+語(yǔ)言編程的優(yōu)勢(shì)是A是一種面向?qū)ο蟮恼Z(yǔ)言,而生成的代碼運(yùn)行時(shí)開銷小。B是一種面向過(guò)程的語(yǔ)言,用自頂向下設(shè)計(jì)方法進(jìn)行設(shè)計(jì)。C易學(xué),比用VB,Delphi,java語(yǔ)言編程容易。D最適合開發(fā)圖形化的Windows應(yīng)用程序。2 .NET框架類庫(kù)的名空間是System,使用它編程,要求聲明:Ausing namespace std;B#define namespace System;Cusing namespace System;Dusing System;3 寫一條語(yǔ)句,動(dòng)態(tài)
2、分配100個(gè)char 空間的內(nèi)存,地址賦給ptr :A. char *ptr=new double*100;B. char *ptr=new char 100;C. char char =new char (100);D. char *ptr=malloc( sizeof(char)*100);4. (多選)下面說(shuō)法或設(shè)計(jì)正確的有:A. 用class進(jìn)行類的定義,類的成員在默認(rèn)情況下訪問(wèn)權(quán)限是私有的。B. C+語(yǔ)言的變量聲明必須寫在函數(shù)代碼的開頭地方。C.一個(gè)抽象類,不能實(shí)例化。D. 類的構(gòu)造函數(shù)返回類型是voidE.類的成員變量含有是指針變量時(shí),應(yīng)該考慮設(shè)計(jì)一個(gè)拷貝構(gòu)造函數(shù)。F. 類的靜態(tài)成
3、員函數(shù)不能訪問(wèn)非靜態(tài)成員。G. 設(shè)計(jì)Automobile類,它含有Engine類型的成員變量。H. 設(shè)計(jì)Automobile類,它從Engine類派生。5. 設(shè)計(jì)從輸入流中讀數(shù)據(jù)到CMyObject類型的對(duì)象中,正確的函數(shù)原型是:A. istream read( istream in, CMyObject obj); B. void read>>( istream in, CMyObject& obj); Cistream & operator>>( istream& in, CMyObject obj); Distream & oper
4、ator>>( istream &in, CMyObject & obj); 6 (多選)對(duì)以下的函數(shù)聲明,合法的調(diào)用方式有。void getstr(string &buff, char term=n);Astring str; getstr(str);Bstring buff; getstr(&buff);Cstring str; getstr(str, t);Dchar *buff=”abc”; getstr(buff, t);7. (多選)閱讀本試題三.5題中的程序,對(duì)有標(biāo)注行的說(shuō)明正確的是A(1)學(xué)生所有課程成績(jī)的關(guān)聯(lián)容器。(2)Set課程和
5、成績(jī)。(7)讀數(shù)據(jù)文件B(3)第一個(gè)元素和第二個(gè)元素輸出。(4)學(xué)生所有課程成績(jī)的關(guān)聯(lián)容器。C(5)參數(shù)n表示元素個(gè)數(shù)。(6)返回第index下標(biāo)的元素。二 填空1-2面向?qū)ο蟪绦蛟O(shè)計(jì)語(yǔ)言的主要特征是_其基本模塊是_3對(duì)商場(chǎng)中的商品,冰箱,汽車,家電,電視機(jī),交通工具,自行車,電動(dòng)車設(shè)計(jì)類層次結(jié)構(gòu)圖(畫出結(jié)構(gòu)圖)_4-5. 代碼填空int divide( int a,int b)if(b =0 )_return a/b;int main( )_int x,y; cin>>x>>y;cout<<"x/y="<<divide(x,
6、y);catch(char *e)cout<<e<<endl;return 0;6-10. 復(fù)數(shù)類代碼填空class Complexdouble real;double image;public:Complex()Complex(double r) _ Complex(double r,double i) _operator - (Complex t, Complex u );_ operator - (Complex t, Complex u ) /復(fù)數(shù)減實(shí)現(xiàn)return _11-22.影片跟蹤管理程序填空#include<iostream>#includ
7、e< _ >using namespace std;class Filmpublic:Film(string t,string d) title=t; director=d;string title;string director;_ ;/聲明數(shù)據(jù)打印函數(shù)output;void Film:output() /實(shí)現(xiàn)數(shù)據(jù)打印函數(shù)outputcout<<” title:”<< title<<” director:”<< director<<endl;class _ /聲明導(dǎo)演剪輯片類DirectorCutpublic:Direc
8、torCut(string t,string d, string c):_ changes=c;string changes;virtual void output( )_cout<<” changes:”<< changes<<endl;class _ /聲明外國(guó)影片類ForeignFilmpublic:ForeignFilm(string t,string d, string l): Film(t,d)_ string language;_ /聲明數(shù)據(jù)打印函數(shù)outputFilm:output();cout<<” language:”<
9、< _<<endl;void main( )int select;cin>> select;Film *pFilm;if(select=0)pFilm =new Film(“紅高粱”,”張藝謀”); /實(shí)例化Filmelse if(select=1) /創(chuàng)建DirectorCut對(duì)象_ DirectorCut(“xxx”,”xxxx”,”xxxxxx”);/實(shí)例化DirectorCut else /創(chuàng)建ForeignFilm對(duì)象_(“HarryPotter”,”xxxx”,” English”); pFilm->output();_ pFilm; /銷毀對(duì)象
10、23-27查找數(shù)組list中數(shù)據(jù)key,設(shè)計(jì)其摸板函數(shù)。成功返回其下標(biāo),否則返回-1。template<_>_ find( _ ) / 查找key for( _ ) if( listi = = key )return i;_;三 閱讀程序1寫出輸出結(jié)果: _string s = "Object-Oriented Programming in "s += "C+"cout<<s<<"n"2寫出輸出結(jié)果: _int *p1=new int;int *p2=new int;if(p1=p2)cout<
11、;<” p1與p2相等”<<end;else cout<<” p1與p2不相等”<<end;3寫出輸出結(jié)果: _class B protected: virtual void f( ) cout<<”B”<<endl; public:void g( ) f( ); ;class D : public Bprotected: virtual void f( ) cout<<”D”<<endl;void main( ) D d;d.g( ); 4寫出輸出結(jié)果: _#include "stdafx.h
12、" #include <sstream> #include <iostream>using namespace std;int main()string val="10 1000.0 2000.0"int age=40; char* name="王偉"istringstream sin(val);double r,salary1,salary2;sin>>r>>salary1>>salary2;double salary=age*r+salary1+salary2; ostringst
13、ream sout;sout<<"姓名 "<<name<<" 工齡 "<<age<<" 工資 "<<salary;string str=sout.str();cout<<str<<endl;return 0;5學(xué)生數(shù)據(jù)庫(kù)查詢打印程序,寫出輸出結(jié)果:_#include "stdafx.h" #include <iostream>#include <fstream> #include <stri
14、ng>#include <map> #include <deque> #include<algorithm>using namespace std;class CStudentmap<string,int> courseScores; / (1)public:string m_name;string m_ID;CStudent() CStudent(string id,string name)m_ID=id; m_name=name;void setCourseScore(string courseName,int score)/(2)co
15、urseScorescourseName=score;void printScore() for(map<string,int>:iterator p=courseScores.begin();p!=courseScores.end(); p+)cout<<p->first<<"t"<<p->second<<endl; /(3);class Crow /行int n;deque<string> cells; /(4)public:CRow(int n) : cells(n) / (5)thi
16、s->n=n;string& operator(int index) /(6)return cellsindex;void load(istream &in)for(int i=0;i<n;i+)in>>cellsi;class CDBManagedeque<CRow> m_stuTable;deque<CRow> m_scoreTable;deque<CStudent> stus;public:void ReadDatabase(const char* filename) /(7)ifstream ifile(fil
17、ename);while(ifile) string type;ifile>>type;if(type="Student")CRow row(2);row.load(ifile);m_stuTable.push_back(row);else if(type="Score")CRow row(3);row.load(ifile);m_scoreTable.push_back(row);elsebreak;resetStuData();void Report(string studentID) / (8)CStudent stu;if(true=
18、 findStu(studentID,stu)cout<<stu.m_name<<"成績(jī)"<<endl;stu.printScore();cout<<endl;void Report() /(9)cout<<"t成績(jī)表"<<endl;sort(stus.begin(),stus.end(),IdCompFunc);deque<CStudent>:iterator it;for( it=stus.begin();it!=stus.end();it+)CStudent&
19、; stu=*it;cout<<stu.m_name<<" "<<stu.m_ID<<endl;stu.printScore();private:void resetStuData()stus.clear();for( int i=0;i<m_stuTable.size();i+)CRow stuRow=m_stuTablei;string studentID=stuRow0;CStudent stu=CStudent(studentID,stuRow1);for( int j=0;j<m_scoreTable.s
20、ize();j+)CRow scoreRow=m_scoreTablej;if( scoreRow1 = studentID)int score=atoi(scoreRow2.c_str();stu.setCourseScore(scoreRow0,score);stus.push_back(stu);bool findStu(string studentID,CStudent &stu)deque<CStudent>:iterator it;for( it=stus.begin();it!=stus.end();it+)if(it->m_ID = studentID
21、)stu=*it;return true;return false;static bool IdCompFunc(CStudent& stu1,CStudent& stu2)return stu1.m_ID < stu2.m_ID;int main()CDBManage manage;manage.ReadDatabase("DBData.txt");manage.Report("010002");manage.Report();return 0;數(shù)據(jù)文件DBData.txt中有數(shù)據(jù)如下:Student 020001 張三Stude
22、nt 010002 李四Score 數(shù)學(xué) 020001 80Score 數(shù)學(xué) 010002 70Score 物理 010002 60Score 政治 020001 90四對(duì)有標(biāo)號(hào)的行,有錯(cuò)標(biāo)記X,無(wú)錯(cuò)標(biāo)記,可以修改的修改。class IObjectpublic:virtual void v(int x) = 0; /1_ /2 _ class BC : IObject /3 _ int x;static int s;const int c;public:BC( ): c(0) /4_ BC(int a) x=a; c=0; /5_void BC( ) /6 _ int & getX(
23、) return this->x; /7_ static void statictX(int a)x=a; /8_ int getC( )return c; /9_ static void setS( int a) s=a; /10_int getS()return this->s; /11_virtual void v(int a) protectedFunc (a); /12_void m(int a) this.privateFunc(a); /13_private:void privateFunc( int a) x=c*a; protected:void protecte
24、dFunc( int a) x=s*a; ;class DC : public BC /14._ public:DC( )DC(int a) BC( a ); / 15 _ DC( int* p) delete p; /16_virtual void v(int a) privateFunc(a); /17_void m(const char * a);void DC: m(const char * a) /18._BC:m(0); /19 privateFunc (1); /20_int BC:s=0; /21 _ int main( ) IObject obj;/22_DC dc;dc.m
25、(10); /23._dc.m("abc"); /24._int *px=dc.getX( ); /25_BC bc;bc.privateFunc(1); /26_tectedFunc(1); /27_BC:statictX(1); /28_IObject *pobj=new BC(2);pobj->v(1); /29 _ delete pobj; /30_ BC *pbc= (BC*)pobj;/31_ BC *pb=&dc; /32 _ BC:m(2); /33_ DC *pdc= dynamic_cast<DC*>(pb); /3
26、4_pdc->v(1); /35_四 設(shè)計(jì)類(任選兩題)1. 設(shè)計(jì)一個(gè)Profession類,包含如下數(shù)據(jù)成員:name,title,credentials,education,avgIncom。類的公有接口要求包括比較Profession的avgIncome的成員函數(shù)CompareIncome和至少有10其他成員函數(shù)。2. 設(shè)計(jì)隊(duì)列模板類Queue,基本要求是要實(shí)現(xiàn)Push入隊(duì)和Pop出隊(duì)的先進(jìn)先出操作,并編一個(gè)main() 函數(shù)測(cè)試它。3 . 實(shí)現(xiàn)一個(gè)Shape類層次,以Shape為抽象基類,從Shape派生出Point,Circle,Rectangle類,基本行為是MoveTo,D
27、raw,要求每個(gè)類都覆蓋draw函數(shù),用來(lái)輸出對(duì)象的數(shù)據(jù),并編一個(gè)main() 函數(shù)測(cè)試它。/完/標(biāo)準(zhǔn)答案五 選擇(每個(gè)2分,共14分。)1.A2.C3.B4.ACEFG5.D6.AC7.ACD六 填空1.封裝繼承多態(tài)(填空每空1分 ,共27分)2.類汽車3. 商品家電交通工具冰箱電視機(jī)自行車電動(dòng)車4-5. throw "er" try6-10. real=r; image=0; real=r; image=i;friend Complex Complex Complex(t.real-u.image,t.real-u.image);11-22 stringvirtual
28、void output()DirectorCut : public FilmFilm(t,d)Film:output();ForeignFilm: public FilmLanguage = l;virtual void output( )languagepFilm = newpFilm =new ForeignFilmdelete23-27class Tint T list,T key,int nint i=0;i<n;i+return -1;七 閱讀程序1. Object-Oriented Programming in C+(每題2分,共8分。)2. p1與p2不相等3.D4. 姓名
29、王偉 工齡 40 工資 34005. (分別2分,3分,共5分。)李四成績(jī)數(shù)學(xué)70物理60成績(jī)表李四 010002數(shù)學(xué)70物理60張三020001數(shù)學(xué)80政治90四對(duì)有標(biāo)號(hào)的行,有錯(cuò)標(biāo)記X,無(wú)錯(cuò)標(biāo)記,可以修改的修改。(-0.5分共9分X -1分(指出錯(cuò)誤0.5分 修改0.5分)共17分,共26分。)1. 2. X;3. X public IObject4. 5 . X BC(int a): c(0) x=a; 6 . X BC( )7. 8. X9. 10. 11. X return s;12. 13. X privateFunc(a); 14. 15. X DC(int a) :BC( a
30、) 16 . X DC() 17 .X18. 19. 20. X21. 22.X23. X24. 25. X int x=dc.getX( );26.X27. X28. 29. 30. 31. 32. 33.X34. 35. 五。設(shè)計(jì)類(任選兩題) (每題10分,共20分。)1. (總體、屬性、方法、main、CompareIncome分別2分,共10分)參考程序#include "stdafx.h"#include <iostream>#include <string>using namespace std;class Professionstri
31、ng name;string title;string credentials;string education;double avgIncom;public:Profession()Profession(string name) this->name=name;int CompareIncome( Profession &profes)if( avgIncom < profes.getavgIncom()return -1;else if( avgIncom = profes.getavgIncom() )return 0;else return 1;static int
32、 CompareIncome( Profession &profes1,Profession &profes2)if( profes1.getavgIncom()<profes2.getavgIncom() return -1;else if( profes1.getavgIncom()> profes2.getavgIncom() return 1;else return 0;string getname()return name;string gettitle()return title;string getcredentials()return credent
33、ials;string geteducation()return education;double getavgIncom()return avgIncom;void setname( string name ) this->name=name;void settitle( string title ) this->title=title;void setcredentials( string credentials ) this->credentials=credentials;void seteducation( string education ) this->e
34、ducation=education;void setavgIncom( double avgIncom ) this->avgIncom=avgIncom;int _tmain(int argc, _TCHAR* argv)Profession prof2;for(int i=0;i<2;i+)string name;string title;string credentials;string education;double avgIncom;cin>>name>>title>>credentials>>education>
35、>avgIncom;profi.setname(name);profi.settitle(title);profi.setcredentials(credentials);profi.seteducation(education);profi.setavgIncom(avgIncom);for(i=0;i<2;i+)cout<<profi.getname()<<"t"<<profi.gettitle()<<"t"<<profi.getcredentials()<<&quo
36、t;t"<<profi.geteducation()<<"t"<<profi.getavgIncom()<<"t"<<endl;int comp=Profession:CompareIncome( prof0,prof1 );cout<<prof0.getname()<<"avgIncom 比"<< prof0.getname();if( comp < 0 )cout<<"少"<<
37、endl;else if( comp > 0 )cout<<"多"<<endl;elsecout<<"相同"<<endl;return 0;2. (總體、template、方法、main、算法分別2分,共10分)參考程序template<class T,int size>class Queue public:Queue()elements=new Tsize;head=tail=0;count=0; virtual Queue() delete elements;void push( co
38、nst T& e );T pop()T tem= elementshead; count-;head=(head+1)%size;return tem; private:T *elements;int head; int tail;int count;template<class T,int size> void Queue<T,size>: push(const T&e)elementstail=e; count+;tail=(tail+1)%size; void main( ) Queue<string,100> queue; /創(chuàng)建有100個(gè)元素的隊(duì)列queue.push("aaaa"); queue.push("bbbbb");cout<<queue.pop()<<endl; cout<<queue.pop()<<endl;3. (Shape、Circle 、Point、Rectangle 、main分別2分,共10分)
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 數(shù)字技術(shù)在雕塑藝術(shù)中的創(chuàng)新運(yùn)用-深度研究
- 戰(zhàn)略資源整合策略-深度研究
- 分布式光伏發(fā)電市場(chǎng)分析-深度研究
- 大氣邊界層湍流研究-深度研究
- X光影像輔助診斷系統(tǒng)-深度研究
- 2025年廣西水利電力職業(yè)技術(shù)學(xué)院高職單招語(yǔ)文2018-2024歷年參考題庫(kù)頻考點(diǎn)含答案解析
- 2025年廣東交通職業(yè)技術(shù)學(xué)院高職單招職業(yè)適應(yīng)性測(cè)試近5年常考版參考題庫(kù)含答案解析
- 2025年常州紡織服裝職業(yè)技術(shù)學(xué)院高職單招高職單招英語(yǔ)2016-2024歷年頻考點(diǎn)試題含答案解析
- 2025年山西信息職業(yè)技術(shù)學(xué)院高職單招職業(yè)適應(yīng)性測(cè)試近5年常考版參考題庫(kù)含答案解析
- 2025至2030年中國(guó)甘蔗專用肥數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 2024年高純氮化鋁粉體項(xiàng)目可行性分析報(bào)告
- 安檢人員培訓(xùn)
- 山東省濰坊市2024-2025學(xué)年高三上學(xué)期1月期末 英語(yǔ)試題
- 危險(xiǎn)性較大分部分項(xiàng)工程及施工現(xiàn)場(chǎng)易發(fā)生重大事故的部位、環(huán)節(jié)的預(yù)防監(jiān)控措施
- 《榜樣9》觀后感心得體會(huì)四
- 2023事業(yè)單位筆試《公共基礎(chǔ)知識(shí)》備考題庫(kù)(含答案)
- 化學(xué)-廣東省廣州市2024-2025學(xué)年高一上學(xué)期期末檢測(cè)卷(一)試題和答案
- 2025四川中煙招聘高頻重點(diǎn)提升(共500題)附帶答案詳解
- EHS工程師招聘筆試題與參考答案(某大型央企)2024年
- 營(yíng)銷策劃 -麗亭酒店品牌年度傳播規(guī)劃方案
- 2025年中國(guó)蛋糕行業(yè)市場(chǎng)規(guī)模及發(fā)展前景研究報(bào)告(智研咨詢發(fā)布)
評(píng)論
0/150
提交評(píng)論