




已阅读5页,还剩10页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
学 生 实 验 报 告 学 院: 软件与通信工程学院 课程名称: C+课程设计 专业班级: 10软件1班 姓 名: 黄道炜 学 号: 0103815 学生实验报告(5)学生姓名黄道炜学号0103815同组人:无实验项目公司员工管理信息系统必修 选修演示性实验 验证性实验 操作性实验 综合性实验实验地点W102实验仪器台号指导教师赵晓平实验日期及节次2011.11.9(三) 567节2011.11.16(三) 567节2011.11.23(三) 567节一、实验综述1、实验目的及要求利用文件处理方式,并综合运用C+面向对象编程实现一个公司员工管理信息系统。实验题:设计一个虚基类Staff(员工),包含编号、姓名和年龄保护数据成员以及相关的成员函数;由Staff派生出工程师类Engineer,包含专业和职称保护数据成员和相关的成员函数;再由Staff派生出领导类Leader,包括职务和部门保护数据成员和相关的成员函数;然后由Engineer和Leader类派生出主任工程师类Chairman。设计一个利用文件处理方式实现对公司员工(包括工程师、领导和主任工程师)进行管理,具备增加数据、更新数据、查询数据、删除数据以及重组文件的功能。要求将公司人员信息存储在数据文件staff.dat中,为存储方便,可以定义索引文件,在索引文件中,每一项包括删除标志、编号,记录在数据文件staff.dat中的相对位置和人员类型,使用索引对数据文件进行定位操作。实验要求:认真完成实验题,能正确运行,提交实验报告并上传程序,实验报告要求写出操作步骤、结果、问题、解决方法、体会等。2、实验仪器、设备或软件 计算机、VC+6.0、office、相关的操作系统等。二、实验过程(实验步骤、记录、数据、分析)#include #include#includeusing namespace std;#define MAX_ERROR_MESSAGE_LEN 100 class Error private: char message MAX_ERROR_MESSAGE_LEN; public: Error(char mes=一般性异常!)strcpy(message,mes); void Show() const coutmessageendl; ; char GetChar(istream &in=cin) char ch; while (ch=in.peek()!=EOF &(ch=in.get()= |ch=/t); return ch; bool UserSaysYes() char ch; bool initialResponse=true; do if(initialResponse) cout(y,n)?; else cout用y或n回答:; while(ch=GetChar()=/n); initialResponse=false; while (ch!=y&ch!=Y&ch!=n&ch!=N); while (GetChar() !=/n) if (ch=y|ch=Y) return true; else return false; class Staffprotected:char num8;char name12;int age;public:Staff() virtual Staff() const char *GetNum() const return num;virtual void Input()=0;virtual void Show() const=0;virtual void Read(fstream &f) const=0;virtual void Write(fstream &f) const=0;class Engineer:virtual public Staffprotected:char major12;char prof12;public:Engineer() virtual Engineer() void Input()coutnum;coutname;coutage;coutmajor;coutprof;void Show() constcoutsetw(8)numsetw(12)namesetw(5)agesetw(12)majorsetw(12)profendl;void Read(fstream &f) const f.read(char *)this,sizeof(Engineer);void Write(fstream &f) const f.write(char *)this,sizeof(Engineer);class Leader:virtual public Staffprotected:char job12;char dep12;public:Leader()virtual Leader()void Input()coutnum;coutname;coutage;coutjob;coutdep;void Show() constcoutsetw(8)numsetw(12)namesetw(5)agesetw(12)jobsetw(12)dependl;void Read(fstream &f) const f.read(char *)this,sizeof(Leader);void Write(fstream &f) const f.write(char *)this,sizeof(Leader);class Chairman:public Engineer,public Leaderpublic:Chairman()virtual Chairman()void Input()coutnum;coutname;coutage;coutmajor;coutprof;coutjob;coutdep;void Show() constcoutsetw(8)numsetw(12)namesetw(5)agesetw(12)majorsetw(12)profsetw(12)jobsetw(12)dependl;void Read(fstream &f) const f.read(char *)this,sizeof(Chairman);void Write(fstream &f) const f.write(char *)this,sizeof(Chairman);struct IndexTypebool delTag;char num8;int position;char staffType;#define NUM_OF_INCREMENT 1000class StaffManageprivate:fstream file;IndexType *indexTable;int maxSize;int count;void AddIndexItem(const IndexType &e);void AddData();void UpdataData();void SearchData();void DeleteData();void Pack();public:StaffManage();virtual StaffManage();void Run();StaffManage:StaffManage()ifstream indexFile(staff.idx,ios:binary);if(!indexFile.fail()indexFile.seekg(0,ios:end);count=indexFile.tellg() /sizeof(IndexType); maxSize=count+NUM_OF_INCREMENT; indexTable=new IndexTypemaxSize;indexFile.seekg(0,ios:beg);int i=0;indexFile.read(char*)&indexTablei+,sizeof(IndexType);while(!indexFile.eof()indexFile.read(char*)&indexTablei+,sizeof(IndexType);indexFile.close();elsecount=0;maxSize=count+NUM_OF_INCREMENT;indexTable=new IndexTypemaxSize;ifstream iFile(staff.dat);if(iFile.fail()ofstream oFile(staff.dat);if(oFile.fail() throw(打开文件失败!);oFile.close();elseiFile.close();file.open(staff.dat,ios:in|ios:out|ios:binary);if(file.fail() throw(打开文件失败!);StaffManage:StaffManage()ofstream indexFile(staff.idx,ios:binary);for(int i=0;i=maxSize)maxSize+=NUM_OF_INCREMENT;IndexType * tmpIndexTable=new IndexTypemaxSize;for(int i=0;icount;i+)tmpIndexTablei=indexTablei;deleteindexTable;indexTable=tmpIndexTable;indexTablecount+=e;void StaffManage:AddData()Staff *pStaff;IndexType item;item.delTag=false;file.seekg(0,ios:end);dodocoutitem.staffType;item.staffType=tolower(item.staffType);while(item.staffType!=e&item.staffType!=l&item.staffType!=c);if(item.staffType=e) pStaff=new Engineer;else if(item.staffType=l) pStaff=new Leader;else pStaff=new Chairman;pStaff-Input();strcpy(item.num,pStaff-GetNum();item.position=file.tellg();AddIndexItem(item);pStaff-Write(file);delete pStaff;cout继续添加吗;while(UserSaysYes();void StaffManage:UpdataData()Staff *pStaff;IndexType item;item.delTag=false;char num12;coutnum;int pos;for(pos=0;poscount;pos+)if(strcmp(num,indexTablepos.num)=0&!indexTablepos.delTag)break;if(posRead(file);pStaff-Show();docoutitem.staffType;item.staffType=tolower(item.staffType);while(item.staffType!=e&item.staffType!=l&item.staffType!=c);if(item.staffType=e) pStaff=new Engineer;else if(item.staffType=l) pStaff=new Leader;else pStaff=new Chairman;pStaff-Input();if(item.staffType=indexTablepos.staffType)strcpy(indexTablepos.num,pStaff-GetNum();file.seekg(indexTablepos.position,ios:beg);elseindexTablepos.delTag=true;strcpy(item.num,pStaff-GetNum();file.seekg(0,ios:end);item.position=file.tellg();AddIndexItem(item);pStaff-Write(file);delete pStaff;elsecout查无此人!endl;file.clear();void StaffManage:SearchData()Staff *pStaff;char num12;coutnum;int pos;for(pos=0;poscount;pos+)if(strcmp(num,indexTablepos.num)=0&!indexTablepos.delTag)break;if(posRead(file);pStaff-Show();delete pStaff;elsecout查无此人!endl;file.clear();void StaffManage:DeleteData()Staff *pStaff;IndexType item;item.delTag=false;char num12;coutnum;int pos;for(pos=0;poscount;pos+)if(strcmp(num,indexTablepos.num)=0&!indexTablepos.delTag)break;if(posRead(file);cout被删除记录为:Show();indexTablepos.delTag=true;delete pStaff;cout删除成功!endl;elsecout删除失败!endl;file.clear();void StaffManage:Pack()ofstream oFile(tem.dat);oFile.close();fstream outFile(tem.dat,ios:app|ios:binary);Staff *pStaff;int cur_count=0;for(int pos=0;posRead(file);pStaff-Write(outFile);
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 热敷与低频电刺激协同作用-洞察及研究
- 手指画树叶课件
- 公司管理者遵守公司既定制度
- 视听行为分析-洞察及研究
- 公司复印机买卖合同5篇
- 2025-2026学年九年级上册期中模拟试卷(一)(含答案)
- 2024-2025学年四川省成都市龙泉驿区八年级(下)期中数学试卷(含部分答案)
- 橡胶厂考勤管理规范制度
- 自然冷却技术优化-洞察及研究
- 采购成本管理技术与谈判技巧培训(采购培训)
- 石群邱关源电路(第1至7单元)白底课件
- GB/T 40529-2021船舶与海洋技术起货绞车
- GB 31603-2015食品安全国家标准食品接触材料及制品生产通用卫生规范
- GA 392-2009警服雨衣
- 关于公布2016年度中国电力优质工程奖评审结果的通知
- 送达地址确认书(诉讼类范本)
- 商务礼仪情景剧剧本范文(通用5篇)
- 幼教培训课件:《家园共育体系建构与实施策略》
- 《电子制造技术-电子封装》配套教学课件
- 机关档案管理工作培训PPT课件
- 厦华验厂不良整改计划表
评论
0/150
提交评论