




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
#include #include #include #include using namespace std; struct EMPchar name25;float salary;int deleted;void main()EMP e;strcpy(,NULL);e.salary = 0;e.deleted = 0;while(1)char c;cout;cin.get(c);if(c = n)coutName: ;;cine.salary;e.deleted = 0;else if(c = s)if(strcmp(,NULL) = 0)coutnEnter employee data before trying to save;continue;ofstream file;file.open(EMP.DAT,ios:app|ios:binary);if(! file)coutnFailed to save data;continue;file.write(char *)&e,sizeof(e);file.close();coutnFile saved;else if(c = l)ifstream infile ;infile.open (EMP.DAT,ios:binary);if(! infile)coutnFailed to read file;continue ;long curpos,length;curpos = infile.tellg();infile.seekg(0L,ios:end);length = infile.tellg();infile.seekg(0L,ios:beg);long num_recs = length / sizeof(e);for(long l = 0;lnum_recs;l+)infile.read(char *)&e,sizeof(e);coutnName: ;coutnSalary: e.salary;infile.close();coutnntRecords: num_recs;else if(c = h)coutnn - Newns - Savenl - Listnq - Quit;else if(c = q)break;else if(c = f)ifstream infile1;infile1.open(EMP.DAT,ios:binary);if(! infile1)coutFailed to open file;continue;coutEnter employee name: f;long curpos,length;curpos = infile1.tellg();infile1.seekg(0L,ios:end);length = infile1.tellg();infile1.seekg(0L,ios:beg);long num_recs = length / sizeof(e);int found = 0;for(long l = 0;lnum_recs;l+)infile1.read(char *)&e,sizeof(e);if(strcmp( ,f) = 0)coutnName: ;coutnSalary: e.salary ;found = 1;if(found = 0)coutRecord not found ;infile1.close ();else if(c = d)ifstream infile2;ofstream temp_file;infile2.open (EMP.DAT,ios:binary);if(! infile2)coutFailed to load data;continue ;temp_file.open(EMP_TEMP.DAT,ios:binary);if(! temp_file)coutFailed to creat temp file;continue;coutf;long curpos,length;curpos = infile2.tellg();infile2.seekg(0L,ios:end);length = infile2.tellg();infile2.seekg(0L,ios:beg);long num_recs = length / sizeof(e);int found = 0;for(long l = 0;lnum_recs;l+)infile2.read(char *)&e,sizeof(e);if(strcmp( ,f) = 0)e.deleted = 1;found = 1;temp_file.write (char *)&e,sizeof(e);infile2.close();temp_file.close ();if(found = 0)coutRecord not found ;continue ;ofstream outfile(EMP.DAT,ios:binary);ifstream infile3(EMP_TEMP.DAT,ios:binary);curpos = infile3.tellg ();infile3.seekg(0L,ios:end);length = infile3.tellg();infile3.seekg(0L,ios:beg);num_recs = length / sizeof(e);for(l = 0;lnum_recs;l+)infile3.read(char *)&e,sizeof(e);if(e.deleted = 0)outfile.write (char *)&e,sizeof(e);infile3.close ();outfile.close ();coutRecord deleted;else if(c = e)ifstream infile4;infile4.open (EMP.DAT,ios:binary);if(! infile4)coutFailed to open file;continue ;coutf;long curpos,length;curpos = infile4.tellg();infile4.seekg(0L,ios:end);length = infile4.tellg();infile4.seekg(0L,ios:beg);long num_recs = length / sizeof(e);int found = 0;char new_name25;float new_sal;EMP new_emp;long write_at;for(long l = 0;lnum_recs;l+)infile4.read(char *)&e,sizeof(e);if(strcmp( ,f) = 0)coutnew_name;coutnew_sal;strcpy(new_,new_name);new_emp.salary = new_sal;new_emp.deleted = 0;found = 1;write_at = l;break;infile4.close ();if(found = 1)write_at = write_at *sizeof(new_emp);fstream file (EMP.DAT,ios:binary|ios:in|ios:out);if(! file)coutEditing failed;continue;fi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 劳动合同劳动合同(标准版)
- 快递员工劳动合同(标准版)
- 固定资产项目贷款合同(标准版)
- 对口单招地理试卷及答案
- 2025年间硝基苯酚项目申请报告模范
- 2025年铁路旅客运输服务项目提案报告
- 小学趣味课堂试卷及答案
- 高一上的生物试卷及答案
- 法规对安全管理培训时间课件
- 团员多选考试试题及答案
- 教科版五年级上册科学期中测试卷附答案(夺分金卷)
- 《环氧树脂应用》课件
- 中职第1课 社会主义在中国的确立和探索试题
- 2025年辽宁省交投集团招聘笔试参考题库含答案解析
- 2024年版高尔夫球场场地租赁及会员服务协议3篇
- 香港 信托合同范本
- 建筑物拆除场地清理垃圾外运施工方案
- 国家开放大学《Web开发基础》形考任务实验1-5参考答案
- 断亲协议书模板
- 中秋国庆假期安全教育
- GB/T 19808-2005塑料管材和管件公称外径大于或等于90mm的聚乙烯电熔组件的拉伸剥离试验
评论
0/150
提交评论