




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第 1 页 ( 共 4 页 )上海大学 2006 2007 学年 冬 季学期B试卷课程名:面向对象程序设计 课程号:093660463000学分: 5 应试人声明: 我保证遵守上海大学学生手册中的上海大学考场规则,如有考试违纪、作弊行为,愿意接受上海大学学生考试违纪、作弊行为界定及处分规定的纪律处分。应试人 应试人学号 应试人所在院系 题号一二三四五六七八九得分一 。填空 (46分)1. 面向对象程序设计语言的主要特征是_2-4. 在面向对象程序设计中,一辆汽车有一个引擎,表现为类Automobile具有一个Engine _;喷漆设备是机器设备的一种,表现为类PaintMachine是类Machine的_,或对象(变量) paintMachine是类Machine的_.5.名空间的用途是_6.使用C+标准模板库必须指定头文件,并用如下语句行指定名空间_7.写一条语句,用cin读入一个int 型值到i _8.写一条语句,用c+方法分配一个类型double 的存储空间,并把它的地址存到ptr _9. 用C+标准库,写两条语句,连接字符串,设字符串str初值”abcd”,然后连接串”efg”:_成绩10-13.复数类代码填空class Complexdouble real;double image;public:Complex()Complex(double r,double i)_operator + (_) Complex v(real+u.real,image+u.image);return v;14-15以下是读数据文件的编程#include #include using namespace std;void main( )double x,y;tryifstream file(“data.txt”);_coutx” “yendl;_cout”不能打开文件”endl;第 2 页 ( 共 4 页 )一 阅读程序,给出输出结果 (20分)1._ #include#includeclass Studentint num; char name20;public:Student()Student(int n,char *p)num =n;strcpy(name,p);void set (int n,char *p)num=n;strcpy(name,p);void display(void)coutnum,nameendl;2._#include templatevoid swap1(T a,T b) T temp=a;a=b;b=temp;templatevoid swap2(T &a,T &b) T temp=a;a=b;b=temp;int main()int x1=1,y1=2;swap1(x1,y1);coutx1” “y1endl;double x2=0.1,y2=0.2;swap2(x2,y2);coutx2” “y2endl;return 0;int main()Student a(1001,liming),b(1002,zhanghua);a.display();b.display();Student c;char *temp;int num;temp=wangfei; num=1003;c.set(1003,temp);c.display();return 0;3. _class Bprotected:virtual void f( )cout”VB”endl;public:void g( ) f(); void h( ) cout”B”endl;4. _class ISink public: virtual void OnEventHandle(int e)=0; ;class CEventmap sinkObjs;public:void addConnect(ISink*sink)sinkObjssink=sink; cout”订阅事件”endl;void FireEvent(int e)int count=0;map:iterator it=sinkObjs.begin();while(it!=sinkObjs.end()map:value_type &v=*it+;v.second-OnEventHandle(e);count +;cout”激发了”count”个响应”endl;class D : public Bprotected:virtual void f( )cout”VD”endl;public:void h( ) cout”D”endl;void main( )D d;d.g( );B & b=d;b.h();第 3 页 ( 共 4 页 )class CEventSrc public:CEvent event; /事件void modifyData(int x)cout“通知事件接收者“endl;event.FireEvent(x);class CEventSink : public ISinkpublic:CEventSink()virtual void OnEventHandle(int e) /响应事件cout”响应事件:”数据变化到eendl;void main( )CEventSrc src;CEventSink sink1;src.event.addConnect(&sink1); src. modifyData(100);src. modifyData(200);三.对有标号的行改错,无错写无 (24 分)class Pointint x;int y;protected:/1. _Point(int a,int b)x=a;y=b;void MoveTo(int newX,int newY)/ 2. _ x=newX;y=newY;void Display()/ 3. _cout”(”x”,”y”)”;class Circle : public Point /4._int r;public:Circle(int a,int b,int r) x=a;y=b ;/ 5. _r=R;void Display() coutDisplay() ;int main( )Circle* objs2;/7._objs0= Point(100,200);/8._objs1=new Circle(200,300,30); objs0-Display();/*要求Display Point */objs1.Display();/*要求Display Circle */9._Show(objs0); /*要求Display Circle */10._Circle *pcir= objs1;coutrendl;/11_12. 说明下面db1函数的错误_int & db1( int i ) int j = 2 * i ; return j ; 第 4 页 ( 共 4 页
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论