面向对象真题回忆版.doc_第1页
面向对象真题回忆版.doc_第2页
面向对象真题回忆版.doc_第3页
面向对象真题回忆版.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、有一个多行文本的缓冲区,设计接口完成以下功能(18分,每题3分)(1)计算缓冲区的行数(2)计算某行有多少个字符(3)在缓冲区某位置插入n个字符(或插入一个字符串)(4)在缓冲区指定位置删除n个字符(5)在缓冲区指定位置替换n个字符(6)返回缓冲区指定位置某个字段的个数/ 文本缓冲区处理接口class CBufInterfacepublic:virtual int GetLineCount() = 0;/ 计算缓冲区的行数/ 返回值:缓冲区函数virtual int GetTextCount(int nLine) = 0;/ 计算某行有多少个字符/ 返回值:某行的字符数/ 参数:nLine行号virtual int InsertIn(int nIndex, char* pchar, int nLength) = 0;/ 在缓冲区某位置插入n个字符(或插入一个字符串)/ 返回值:插入字符串后缓冲区长度/ 参数:nIndex字符插入位置,pchar待插入字符串首地址,nLength待插入字符串长度virtual int DeleteIn(int nIndex, int nLength) = 0;/ 在缓冲区指定位置删除n个字符/ 返回值:删除字符后缓冲区长度/ 参数:nIndex第一个被删除字符位置,nLength删除的字符个数virtual int Replace(int nIndex, char* pchar, int nLength) = 0; / 在缓冲区指定位置替换n个字符/ 返回值:替换字符串后缓冲区长度/ 参数:nIndex代替换的第一个字符位置,pchar新字符串首地址,nLength新字符串长度virtual int Find(int nStart, int nLength, char* pchar) = 0;/ 返回缓冲区指定位置某个字段的个数/ 返回值:指定位置内某字段出现个数/ 参数:nStart开始位置,nLength查找范围,pchar匹配字段;/ 根据具体的缓冲区类型实现接口class CConcreteBuf: public CBufInterfaceprivate:concretebuf*m_pbuf;public:CConcreteBuf(concretebuf* pbuf);int GetLineCount();int GetTextCount(int nLine);int InsertIn(int nIndex, char* pchar, int nLength);int DeleteIn(int nIndex, int nLength) = 0;int Replace(int nIndex, char* pchar, int nLength);int Find(int nStart, int nLength, char* pchar);2、有一个记事本软件系统,用来记录一年中每天的事务记录,事务记录有三种:约见记录(会见人的信息(一个或多个)、时间、地点)、会议记录(主持部门、时间、地点、内容摘要)、记事记录(内容、时间)(42分)(1)画出类图(写出数据结构和类设计)(2)画活动图:指定10-04 10:00-11:00,要求解析出日期和时间,打印输出所有事务记录(3)编写算法实现(2)中的功能/ 日期class CDatepublic:int month;int day;CDate(int m, int d);BOOL operator=(CDate &date);/ 时间clas CTimepublic:int hour;int minute;CTime(int h, int m);BOOL operator=(CTime &time);类图根据以下类设计自己画。/ 记录管理类class CRecordSystemprivate:CObList sets;/ 记录集链表public:void AddRecord(CRecord* p);void DelRecord(CRecord* p);void DelRecord(CDate date);void DelRecord(CDate date, CTime stime, CTime etime);BOOL Find(CDate date, CTime stime, CTime etime);void Print(CDate date, CTime stime, CTime etime);/ 一天的记录集class CSet : public CObjectprivate:CDate date;CObListrecords;/ 记录链表public:void AddRecord(CRecord* p);void DelRecord(CRecord* p);BOOL Find(CTime stime, CTime etime);void Print(CTime stime, CTime etime);/ 记录class CRecord : public CObjectprotected:CTime time;public:virtual CRecord();virtual void Print();void SetTime(CTime time);CTime GetTime();/ 约会记录class CDateRecord : public CRecordprivate:CObList man;CString address;public:void AddMan(CMan* pman);void GetMan(CPtrList &p);void SetAddress(CString str);CString GetAddress();void Print();/ 会议记录class CMeetingRecord : public CRecordprivate:CString department;CString address;CString abstract;public:void SetDepartment(CString str);CString GetDepartment();void SetAddress(CString address);CString GetAddress();void SetAbstract(CString str);CString GetAbstract();void Print();/ 事件记录class CThingRecord : public CRecordprivate:CString content;public:void SetContent(CString str);CString GetContent();void Print();算法:查找指定日期时间的记录输入:日期时间格式10-04 10:00-11:00输出:在标准输出设备上打印出符合条件的记录主函数:int month, day, shour, sminute, ehour, eminute;scanf(%d-%d %d:%d-%d:%d, &month, &day, &shour, &sminute, &ehour, &eminute);CDate date(month, day);CTime stime(shour, sminute);CTime etime(ehour, eminute);recordsystem.Print(date, stime, etime);void CRecordSystem:Print(CDate date, CTime stime, CTime etime)POSITION pos = sets.GetHeadPosition();while(pos)CSet* p = sets.GetNext(pos);if(p-GetDate() = date)p-Printf(CTime stime, CTime etime);r

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论