版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、学生验报告学 院:软件与通信工程学院课程名称:C+ 课程设计专业班级:10 软件 1 班姓 名:黄道炜学 号:0103815学生实验报告( 5)学生姓名黄道炜 学号 0103815同组人:无实验项目公司员工管理信息系统必修 选修演示性实验 验证性实验 操作性实验 综合性实验实验地点W102实验仪器台号指导教师赵晓平实验日期及节次2011.11.9( 三) 567 节2011.11.16( 三) 567 节2011.11.23( 三) 567 节一、实验综述1、实验目的及要求利用文件处理方式, 并综合运用 C+面向对象编程实现一个公司员工管理信息 系统。实验题:设计一个虚基类 Staff (员工
2、),包含编号、姓名和年龄保护数据成员以及相关 的成员函数; 由 Staff 派生出工程师类 Engineer ,包含专业和职称保护数据成员和 相关的成员函数; 再由 Staff 派生出领导类 Leader ,包括职务和部门保护数据成员 和相关的成员函数;然后由 Engineer 和 Leader 类派生出主任工程师类 Chairman。设计一个利用文件处理方式实现对公司员工 (包括工程师、 领导和主任工程师)进行管理,具备增加数据、更新数据、查询数据、删除数据以及重组文件的功能。要求将公司人员信息存储在数据文件 staff.dat 中,为存储方便,可以定义索 引文件,在索引文件中,每一项包括删
3、除标志、编号,记录在数据文件 staff.dat 中的相对位置和人员类型,使用索引对数据文件进行定位操作。实验要求: 认真完成实验题,能正确运行,提交实验报告并上传程序,实验报告要求写出 操作步骤、结果、问题、解决方法、体会等。2、实验仪器、设备或软件计算机、 VC+6.0、 office 、相关的操作系统等。二、实验过程(实验步骤、记录、数据、分析)#include #include #include using namespace std;#define MAX_ERROR_MESSAGE_LEN 100 class Errorprivate:char message MAX_ERROR_
4、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;doif(initialResponse) cout(y,n)?;elsecout 用 y 或 n 回答: ;
5、 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;elsereturn false;class Staffprotected:char num8; char name12; int age;public:Staff() virtual Staff() const char *GetNum() const return num; virtual void Input()=0;virtual v
6、oid 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)n
7、amesetw(5)age setw(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;coutnam
8、e;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()virtu
9、al 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 *)th
10、is,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 Dele
11、teData();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; in
12、dexFile.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()
13、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 * t
14、mpIndexTable=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); dodo coutitem.staffType;item.staffType=tolower(item.st
15、affType);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);dele
16、te 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
17、=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.
18、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;
19、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;poscoun
20、t;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:bina
21、ry);Staff *pStaff;int cur_count=0;for(int pos=0;posRead(file);pStaff-Write(outFile);delete pStaff;indexTablecur_count+=indexTablepos; count=cur_count;file.close();outFile.close();remove(staff.dat);rename(tem.dat,staff.dat); file.open(staff.dat,ios:in|ios:out|ios:binary);void StaffManage:Run()int select; docout 请选择 :endl; cout1cout2cout3cout4cout5cout6增加数据更新数据查询数据删除数据 重组文件endl; endl; endl; endl; endl;退出select; while(cin.get()!
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- Chapter1 Teamwork教学设计小学英语5B香港朗文版
- 2025-2026学年短文两篇九下教学设计
- 第13课 错落有致教学设计小学书法练习指导五年级下册北师大版
- 2025-2026学年水果茶小班教案
- 《GBT 16462.7-2009数控车床和车削中心检验条件 第7部分:在坐标平面内轮廓特性的评定》专题研究报告
- 《GBT 15072.3-2008贵金属合金化学分析方法 金、铂、钯合金中铂量的测定 高锰酸钾电流滴定法》专题研究报告
- 2024年高中语文 第六单元 文无定格 贵在鲜活 第31课 自主赏析 春夜宴从弟桃花园序教学设计 新人教版选修《中国古代诗歌散文欣赏》
- 《GBT 13709-2015 工业用 X 射线管空白详细规范》专题研究报告
- 《GBT 35250-2017 金属间化合物膜过滤器》专题研究报告
- 码头物联网应用技术方案
- 2026春统编版二年级下册道德与法治第四单元教学设计
- 粉末冶金培训课件
- 真菌性皮肤病的实验室诊断技术
- 车辆安全培训内容
- 美修斯增肌仪器培训课件
- 雨课堂学堂在线学堂云医学英语EMP( 安徽医科大)单元测试考核答案
- 2025年安徽林业职业技术学院单招职业适应性测试题库带答案解析
- Jetpack Compose入门到精通完整版
- 蜱虫防治教学课件
- 认缴股权转让合同范本
- 购买资产包的合同范本
评论
0/150
提交评论