已阅读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浙江丽水缙云县招聘社区专职工作者22人备考题库附答案详解(达标题)
- 2025马鞍山当涂县从社区专职网格员中择优招录社区工作者33人备考题库附答案详解(完整版)
- 2025年延安中学六模试卷及答案
- 2026北京建信股权投资管理有限责任公司校园招聘3人备考题库带答案详解
- 2026年陕西省选调生招录备考题库(面向中央财经大学)附答案详解(b卷)
- 影像技士考试试卷及答案
- 2025下半年四川内江市隆昌市招聘社区工作者75人备考题库及答案详解(真题汇编)
- 2025重庆九龙坡职业教育中心招聘教师2人备考题库及答案详解(名校卷)
- 2025上海市阳光社区青少年事务中心徐汇工作站招聘5人备考题库含答案详解
- 2026九江银行校园招聘备考题库带答案详解
- 超声评估压疮
- 心理放松训练和减压训练
- 电解池高三化学一轮复习新教材新高考教案(2025-2026学年)
- (2025年)(完整版)交通运输行政执法人员专业法律知识考试试卷(含答案)
- 城市供水管网安全评估报告
- 2025中基发展建设工程有限责任公司招聘22人笔试历年参考题库附带答案详解
- 【初中生物】真菌(教学课件)-2025-2026学年人教版生物七年级上册
- 口腔放射知识培训记录课件
- 交通运输行业深度报告:无人机反制系统-奠定低空经济安全发展之基石
- 2025至2030止泻药行业风险投资态势及投融资策略指引报告
- 棉花仓库安全培训课件
评论
0/150
提交评论