公司员工管理信息系统.docx

上传人:牧羊曲112 文档编号:1903626 上传时间:2022-12-25 格式:DOCX 页数:15 大小:179.45KB
返回 下载 相关 举报
公司员工管理信息系统.docx_第1页
第1页 / 共15页
公司员工管理信息系统.docx_第2页
第2页 / 共15页
公司员工管理信息系统.docx_第3页
第3页 / 共15页
公司员工管理信息系统.docx_第4页
第4页 / 共15页
公司员工管理信息系统.docx_第5页
第5页 / 共15页
点击查看更多>>
资源描述

《公司员工管理信息系统.docx》由会员分享,可在线阅读,更多相关《公司员工管理信息系统.docx(15页珍藏版)》请在三一办公上搜索。

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中,为存储方便,可以定义索引文件,在索引文件中,每一项包括删除标志、编号,记录在数据文件staff.dat中

3、的相对位置和人员类型,使用索引对数据文件进行定位操作。实验要求:认真完成实验题,能正确运行,提交实验报告并上传程序,实验报告要求写出操作步骤、结果、问题、解决方法、体会等。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(cha

4、r 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)

5、; 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;v

6、irtual 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)

7、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

8、;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()co

9、utnum;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

10、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:Staf

11、fManage();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;i

12、ndexFile.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

13、() 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;

14、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&ite

15、m.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:U

16、pdataData()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.staffTyp

17、e!=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=

18、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&!i

19、ndexTablepos.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(posRe

20、ad(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);del

21、ete 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;cout1.增加数据endl;cout2.更新数据endl;cout3.查询数据endl;cout4.删除数据endl;cout5.重组文件

22、endl;cout6.退出select;while(cin.get()!=n);switch(select)case 1:AddData();break;case 2:UpdataData();break;case 3:SearchData();break;case 4:DeleteData();break;case 5:Pack();break;while(select!=6); int main() tryStaffManage objStaffManage;objStaffManage.Run(); catch (Error err) err.Show(); system(PAUSE);return 0;三、结论1、实验结果2、分析讨论这个题目要有耐心!四、指导教师评语及成绩:成绩: 指导教师签名: 批阅日期:

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号