已阅读5页,还剩10页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
学 生 实 验 报 告 学 院: 软件与通信工程学院 课程名称: C+课程设计 专业班级: 10软件1班 姓 名: 黄道炜 学 号: 0103815 15 / 15学生实验报告(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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 高校教师信息化教学技能提升计划
- 影视投资合同范本与风险控制指南
- 幼儿教育课程教学反思案例
- 2025浙江宁波象山县水务集团有限公司第四期招聘工作人员1人笔试考试参考题库及答案解析
- 2025年宜昌市中心人民医院高层次人才引进36人笔试考试备考试题及答案解析
- 2025年丽水云和县卫生健康系统紧缺卫生人才引进11人考试笔试模拟试题及答案解析
- 处方点评超常预警执业药师教案
- 高中地理人教版高中地理选修二人类对海洋的探索与认识教案(2025-2026学年)
- 一年级语文下册课文春笋苏教版教案
- 备战中考为梦想奋斗到最后主题班会带内容教案(2025-2026学年)
- 4输变电工程施工质量验收统一表式(电缆工程电气专业)-2024年版
- 公司运维项目管理制度
- 2024年北京市公安局平谷分局招聘勤务辅警真题
- 中职主题班会【集体主义教育】《同心同德-众人划桨开大船》主题班会设计(主)比赛
- 数字普惠金融对农村居民收入增长的影响机制研究
- 文明上网测试题及答案
- 2025年2月22日四川省公务员面试真题及答案解析(行政执法岗)
- 经皮球囊扩张椎体后凸成形术(PKP)及病例分享
- 第四章第二节《工业》第1课时教学设计-2024-2025学年八年级地理上册粤人版
- 活动策划服务投标方案(技术方案)
- Unit 3 reading 说课稿- 2024-2025学年沪教版(2024)七年级英语上册
评论
0/150
提交评论