




已阅读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年秋季部编版初中数学教学设计八年级上册13.1.1 轴对称
- 幼儿园才艺秀活动方案
- 有关学前教育宣传月的设计活动策划方案
- 北京市十五中2026届高二化学第一学期期末监测模拟试题含答案
- 福建闽侯第六中学2026届化学高二第一学期期末考试试题含答案
- 河北省衡水市桃城区武邑中学2026届高三上化学期中学业水平测试试题含解析
- 家电公司解除合同执行细则
- 放学口语考试题及答案
- 大专造价面试题及答案
- 快速入门穿越机-让你迅速懂穿越机
- 广州南方学院(原中山大学南方学院)学校办公室新闻宣传中心新闻管理岗招聘公开引进高层次人才和急需紧缺人才笔试参考题库(共500题)答案详解版
- 儿童呼吸机基本使用
- 起重机械安全日管控、周排查、月调度制度
- 派出所民警心理健康辅导
- 民事诉讼法课件
- 管理学基础(第3版)全套教学课件
- 柿子醋生产技术规程
- 脊髓损伤病人的护理查房课件
- 经典安徒生童话故事100篇
- 劳务服务施工组织方案
评论
0/150
提交评论