版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选优质文档-倾情为你奉上#include <iomanip>#include <iostream>#include <fstream>#include <malloc.h>#include <stdlib.h>#include <string.h>using namespace std;#define NULL 0#define LEN sizeof(struct student) int const N=20;void Menu(); void Pass();int n=0; /定义一个全局变量统计职工人数 /->
2、;定义一个职工信息的结构体struct student char nameN; /用来存放姓名char sexN; /用来存放性别long id; /用来存放编号float paid3; /用来存放工资int total; /用来存放总工资struct student *next;/->职工类class Information public:Information() ; /构造函数. Information() ; /析构函数. student *creat(); /建立链表void output(student *head); /显示职工信息int count(student *he
3、ad); /定义函数count()统计职工总数student *insert(student*head); /指针函数*insert()用来添加职工信息.student *cancel(student *head,long id); /指针函数*cancel()用来删除职工信息.student *find(student *head,long id); /指针函数*find()用来查找职工信息.student *modify(student *head,long id); /指针函数*modife()用来修改职工的信息.void paixu(student *head); /定义paixu()
4、函数将职工的总额从大到小排列并输出void average(student *head); /定义职工工资平均值的函数void save(student *head); /保存文件信息student *Read(); /读取文件信息private:student *p1,*p2,*p3,*head,st; ;Information:Information() cout<<" *n"cout<<" -<<欢迎您使用员工工资管理系统>>-n" cout<<" *nn" Infor
5、mation:Information() cout<<" ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤n"cout<<"
6、n"cout<<" 本系统管理员 n"cout<<" n"cout<<" n"cout<<" -<<谢谢您使用员工工资管理系统>>-n" cout<<" n"cout<<" n"cout<<" 欢迎下次使用 n"cout<<" n"cout<<" n"cout<<&
7、quot; 再见 n"cout<<" n"cout<<" ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤n&quo
8、t;/->建立链表信息student *Information:creat(void) /定义一个指向struct student的结构体指针函数*creat()用来录入职工信息. char chN;n=0; /用来存放职工姓名 p1=p2=(student *)malloc(LEN);/调用malloc()函数用来开辟一个新的存储单元 cout<<" -<<请建立员工信息表,在姓名处键以 # 结束输入!>>-"<<endl;cout<<" 姓名:"cin>>ch;head=N
9、ULL; /给指针head赋初值while (strcmp(ch,"#")!=0) /调用字符比较函数strcmp()用来判断是否继续输入p1=(student *)malloc(LEN); /调用malloc()函数用来开辟一个新的存储单元strcpy(p1->name,ch); /将循环结构前面输入的姓名复制到结构体名为p1的数组name中cout<<" 性别:"cin>>p1->sex;cout<<" 编号:"cin>>p1->id;while(p1->id
10、)<0|(p1->id)>) /判断输入的编号是否有效(个)cout<<" 对不起您的输入错误!请重新输入(>0<): "cin>>p1->id; cout<<" 基本工资:"cin>>p1->paid0;while(p1->paid0)<0|(p1->paid0)>) /判断输入的分数是否有效(>=0 <=)cout<<" 对不起您的输入错误!请重新输入(>0<): "cin>&
11、gt;p1->paid0; cout<<" 加班工资:"cin>>p1->paid1;while(p1->paid1)<0|(p1->paid1)>) /判断输入的分数是否有效(>=0 <=)cout<<" 对不起您的输入错误!请重新输入(>0<): "cin>>p1->paid1; cout<<" 其他奖金:"cin>>p1->paid2;while(p1->paid2)<0|(
12、p1->paid2)>) /判断输入的分数是否有效(>=0 <=)cout<<" 对不起您的输入错误!请重新输入(>0<): "cin>>p1->paid2; p1->total=p1->paid0+p1->paid1+p1->paid2; /计算总额 if(n=0)head=p1; /如果是输入第一组职工信息就将指针p1赋给指针headelse p2->next=p1; /否则将p1赋给p2所指结构体的next指针p2=p1; /将指针p1赋给指针p2n+; /将职工人数n的值
13、加1cout<<"n 姓名:"cin>>ch; /将输入的姓名存放到字符数组ch中p2->next=NULL; /将p2所指结构体的next指针重新赋空值return (head);/将输入的第一组职工信息返回/->定义output()函数将职工的信息从头指针所指内容开始输出void Information:output(student *head) system("cls");if(head=NULL) cout<<" 这是一个空表,请先输入员工信息!n"elsecout<<
14、;"-n"cout<<" *职工工资信息表*n"cout<<"-n" cout<<"|编 号| |姓 名| |性别| |基本工资| |加班工资| |其他奖金| |总额|n"cout<<"-n" p1=head; /将头指针赋给p docout<<setw(6)<<p1->id<<setw(10)<<p1->name<<setw(10)<<p1->sex<
15、<setw(10)<<p1->paid0<<setw(10)<<p1->paid1<<setw(12)<<p1->paid2<<setw(12)<<p1->total<<endl;cout<<"-n" p1=p1->next; /将下一组职工信息的next指针赋给pwhile(p1!=NULL); /若指针p非空则继续,目的是把所有的职工信息都传给指针p然后输出./->统计职工人数的函数int Information:coun
16、t(struct student *head) /定义函数count()统计职工总数if(head=NULL)return(0); /若指针head为空返回值为0else return(1+count(head->next); /函数的递归调用/->添加职工的成绩的函数student *Information:insert( student *head) /插入新结点定义一个指向struct student的结构体指针函数*insert()用来添加职工信息.system("cls");cout<<"t-<<请输入新增员工信息&g
17、t;>-n"<<endl;p1=(student *)malloc(LEN); /使p1指向插入的新结点cout<<" 编号:"cin>>p1->id;while(p1->id)<0|(p1->id)>)cout<<" 对不起您的输入错误!请重新输入(>0<): "cin>>p1->id; /将输入的编号存放到p1所指结构体的数组id中 cout<<" 姓名:"cin>>p1->na
18、me; /将输入的姓名存放到结构体名为p1的数组name中cout<<" 性别:"cin>>p1->sex; cout<<" 基本工资:"cin>>p1->paid0;while(p1->paid0)<0|(p1->paid0)>)cout<<" 对不起您的输入错误!请重新输入(>0<): "cin>>p1->paid0; /将输入的基本工资存放到p1所指结构体的数组paid中cout<<"
19、; 加班工资:"cin>>p1->paid1;while(p1->paid1)<0|(p1->paid1)>)cout<<" 对不起您的输入错误!请重新输入(>0<): "cin>>p1->paid1; /将输入的加班工资存放到p1所指结构体的数组paid中cout<<" 其他奖金:"cin>>p1->paid2;while(p1->paid2)<0|(p1->paid2)>)cout<<&quo
20、t; 对不起您的输入错误!请重新输入(>0<): "cin>>p1->paid2; /将输入的其他奖金存放到p1所指结构体的数组paid中 p1->total=p1->paid0+p1->paid1+p1->paid2;/计算总分 p2=head; /将头指针赋给p2if(head=NULL) /若没调用次函数以前的头指针head为空head=p1;p1->next=NULL; /则将p1赋给头指针head并将p1所指结构体成员指针next赋空值else while(p1->id>p2->id)&&
21、amp;(p2->next!=NULL)p3=p2; /p3指向原p2指向的结点p2=p2->next; /p2后移一个结点if(p1->id<=p2->id)if(head=p2)p1->next=head;head=p1; /插入到第一个结点之前else p3->next=p1;p1->next=p2; /插入到p3所指结点之后elsep2->next=p1;p1->next=NULL; /插入到尾结点之后n+; /将职工人数加1cout<<"t-<<你输入的员工信息已经成功插入>>-
22、"<<endl;return (head);/->删除职工信息student *Information:cancel(student *head,long id) /定义一个指向struct student的结构体指针函数*delete()用来删除考生信息. system("cls");if(head=NULL) /若调用次函数以前的头指针head为空 return(head);elsep1=head; /否则将头指针赋给p1while(id!=p1->id&&p1->next!=NULL) /寻找要删除的结点当p1所
23、指的职工编号不是输入的职工编号并且p1所指的next指针不为空p2=p1;p1=p1->next; /p2指向原p1指向的结点p1后移一个结点if(id=p1->id) /如果输入的职工编号是p1所指的职工编号/结点找到后删除if(p1=head) head=p1->next; /如果head指针和p1指针相等则将下一个结点赋给指针head else p2->next=p1->next; /否则将p1所指结点赋给p2所指结点将要删除的职工信息跳过去cout<<" 删除编号为"<<id<<"的职工n&
24、quot;n-; /将职工人数减1 return(head); /将头指针返回/*修改职工数据*/student *Information:modify(student *head,long id)system("cls");cout<<"t-<<请输入须修改的员工工资信息>>-n"<<endl;p1=(student *)malloc(LEN); /使p1指向输入的结点p1=head; /否则将头指针赋给p1while(id!=p1->id&&p1->next!=NULL)/寻
25、找结点当p1所指的职工编号不是输入的职工编号并且p1所指的next指针不为空p1=p1->next; /p2指向原p1指向的结点p1后移一个结点 if(id=p1->id) /如果要查找的职工编号是p1所指的职工编号cout<<"你需要修改的员工信息如下:n"cout<<"-n"cout<<"|编 号| |姓 名| |性别| |基本工资| |加班工资| |其他奖金| |总额|n"cout<<"-n"cout<<setw(6)<<p1
26、->id<<setw(10)<<p1->name<<setw(10)<<p1->sex<<setw(10)<<p1->paid0<<setw(10)<<p1->paid1<<setw(12)<<p1->paid2<<setw(12)<<p1->total<<endl;cout<<"-n"cout<<" 编号:"cin>>p1
27、->id;while(p1->id)<0|(p1->id)>)cout<<" 对不起您的输入错误!请重新输入(>0<): "cin>>p1->id; /将输入的编号存放到p1所指结构体的数组id中 cout<<" 姓名:"cin>>p1->name; /将输入的姓名存放到结构体名为p1的数组name中cout<<" 性别:"cin>>p1->sex; cout<<" 基本工资:&qu
28、ot;cin>>p1->paid0;while(p1->paid0)<0|(p1->paid0)>)cout<<" 对不起您的输入错误!请重新输入(>0<): "cin>>p1->paid0; /将输入的基本工资存放到p1所指结构体的数组paid中cout<<" 加班工资:"cin>>p1->paid1;while(p1->paid1)<0|(p1->paid1)>)cout<<" 对不起您的输入
29、错误!请重新输入(>0<): "cin>>p1->paid1; /将输入的加班工资存放到p1所指结构体的数组paid中cout<<" 其他奖金:"cin>>p1->paid2;while(p1->paid2)<0|(p1->paid2)>)cout<<" 对不起您的输入错误!请重新输入(>0<): "cin>>p1->paid2; /将输入的其他奖金存放到p1所指结构体的数组paid中 p1->total=p1-&
30、gt;paid0+p1->paid1+p1->paid2; /计算总分 else cout<<" 需要修改的信息中没有编号为"<<id<<"的员工.nn" /没有想要修改的结点信息getchar();return(head);/->查找职工信息student *Information:find(student *head,long id) /定义一个指向struct student的结构体指针函数*find()用来查找职工信息.system("cls");if(head=NULL)
31、 /若调用次函数以前的头指针head为空cout<<" 这是一个空表,请先输入员工信息!n"return(head); elsep1=head; /否则将头指针赋给p1while(id!=p1->id&&p1->next!=NULL)/寻找结点当p1所指的职工编号不是输入的职工编号并且p1所指的next指针不为空p1=p1->next; /p2指向原p1指向的结点p1后移一个结点if(id=p1->id) /如果要查找的职工编号是p1所指的职工编号cout<<"-n"cout<<
32、"|编 号| |姓 名| |性别| |基本工资| |加班工资| |其他奖金| |总额|n"cout<<"-n"cout<<setw(6)<<p1->id<<setw(10)<<p1->name<<setw(10)<<p1->sex<<setw(10)<<p1->paid0<<setw(10)<<p1->paid1<<setw(12)<<p1->paid2<&l
33、t;setw(12)<<p1->total<<endl;cout<<"-n"else cout<<"信息中没有编号为"<<id<<"的员工.n" /结点没找到return(head);/-定义paixu()函数将职工的工资总额从大到小排列并输出void Information:paixu(student *head) system("cls");int i,k,m=0,j;student *pN;/定义一个指向struct student
34、的结构体指针数组p if(head!=NULL)/如果头指针是空则继续 m=count(head);cout<<"-n"cout<<" *员工工资统计表*n"cout<<"-n"cout<<"|编号| |姓名| |性别| |基本工资| |加班工资| |其他奖金| |总额| |名次|n"cout<<"-n"p1=head;for(k=0;k<m;k+)pk=p1;p1=p1->next;for(k=0;k<m-1;k+)
35、 /选择排序法for(j=k+1;j<m;j+)if(pk->total<pj->total)p2=pk;pk=pj;pj=p2; /从大到小排列的指针 for(i=0;i<m;i+)cout<<setw(6)<<pi->id<<setw(8)<<pi->name<<setw(9)<<pi->sex<<setw(10)<<pi->paid0<<setw(10)<<pi->paid1<<setw(10)&l
36、t;<pi->paid2<<setw(10)<<pi->total<<setw(10)<<i+1<<endl;cout<<"-n" /->求各工资的平均值的函数void Information:average(student *head)int k,m;float arg1=0,arg2=0,arg3=0;if(head=NULL)/如果头指针是空则继续cout<<" 这是一个空表,请先输入员工信息!n"elsem=count(head);p1=h
37、ead;for(k=0;k<m;k+)arg1+=p1->paid0;arg2+=p1->paid1;arg3+=p1->paid2;p1=p1->next;arg1/=m;arg2/=m;arg3/=m;cout<<" *各项工资的平均值*n"cout<<"-n"cout<<"tt基本工资的平均值: "<<setw(4)<<arg1<<"n"<<"tt加班工资的平均值: "<
38、<setw(4)<<arg2<<"n"<<"tt奖金的平均值: "<<setw(4)<<arg3<<"n"cout<<"-n"/->保存函数.void Information:save(student *head) system("cls"); ofstream out("data.txt",ios:out); out<<count(head)<<endl;
39、 while(head!=NULL) out<<head->name<<"t" <<head->id<<"t"<<"t" <<head->sex<<"t" <<head->paid0<<"t" <<head->paid1<<"t" <<head->paid2<<"t"
40、 <<head->total<<endl; head=head->next; />读取文件的信息student *Information:Read() system("cls"); int i=0; p1=p2=( student *)malloc(LEN); head=NULL; ifstream in("data.txt",ios:in); in>>i; if(i=0)cout<<" data 文件中的数据为空,请先输入数据!"<<endl; retur
41、n 0; else cout<<"n原文件已保存的信息如下:n" cout<<" "<<endl; cout<<"|姓 名| |编 号| |性别| |基本工资| |加班工资| |其他奖金| |总额|n" cout<<" "<<endl; for(;i>0;i-) p1=(student *)malloc(LEN); in>>>>st.id>>st.sex >>st.paid0&
42、gt;>st.paid1>>st.paid2>>st.total; strcpy(p1->name,); p1->id=st.id; strcpy(p1->sex,st.sex); p1->paid0=st.paid0; p1->paid1=st.paid1; p1->paid2=st.paid2; p1->total=st.total; if(n=0)head=p1; /如果是输入第一组职工信息就将指针p1赋给指针head else p2->next=p1; /否则将p1赋给p2所指结构体的next指
43、针 p2=p1; /将指针p1赋给指针p2 n+; /将n的值加1 /显示读入数据 cout<<" "<<p1->name<<"t" <<p1->id<<" t" << p1->sex <<" t" << p1->paid0 <<" t" << p1->paid1 <<" t" << p1->pai
44、d2 <<" t" << p1->total<<endl; cout<<" "<<endl;cout<<" 数据已经成功读取完毕!nn"<<endl; p2->next=NULL;in.close(); return (head); /->菜单void Menu() Information person; student *head=NULL; int choice; long i; head=person.Read(); do co
45、ut<<"t"<<endl; cout<<"t "<<endl; cout<<"t _ _ _ 欢迎进入员工信息统计管理 _ _ _ "<<endl; cout<<"t "<<endl; cout<<"t"<<endl; cout<<"t "<<endl; cout<<"t 相关操作选项 "<&l
46、t;endl; cout<<"t "<<endl; cout<<"t"<<endl; cout<<"t "<<endl; cout<<"t "<<endl; cout<<"t 1. 员工数据输入 "<<endl; cout<<"t "<<endl; cout<<"t 2. 显示员工工资 "<<
47、;endl; cout<<"t "<<endl; cout<<"t 3. 排序统计工资 "<<endl; cout<<"t "<<endl; cout<<"t 4. 查找员工工资 "<<endl; cout<<"t "<<endl; cout<<"t 5. 增加员工工资 "<<endl; cout<<"t &qu
48、ot;<<endl; cout<<"t 6. 删除员工工资 "<<endl; cout<<"t "<<endl; cout<<"t 7. 修改员工信息 "<<endl; cout<<"t "<<endl; cout<<"t 8. 成功保存信息 "<<endl; cout<<"t "<<endl; cout<<&
49、quot;t 9. 安全退出系统 "<<endl; cout<<"t "<<endl; cout<<"tn"<<endl; cout<<" 请输入您的选择(0-9):" cin>>choice; while(choice<0|choice>9) cout<<" 对不起您的输入错误!请输入您的选择(0-9): " cin>>choice; /head=person.Read(); swit
50、ch(choice) case 1: head=person.creat(); break; case 2: /head=person.Read(); person.output(head); break; case 3: /head=person.Read(); person.paixu(head); person.average(head); cout<<" 参加工作的员工人数为:"<<person.count(head)<<"人nn" break; case 4: /head=person.Read(); cout<<" 请输入要查找的编号:"
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026届河北T8联考高三下学期4月联合测评英语+答案
- 2025杭州电子科技大学信息工程学院教师招聘考试题目及答案
- 2026年江西餐饮服务资格考试及答案
- 洛阳二建试卷试题及答案
- 2026北京市法院系统招聘聘用制审判辅助人员53人建设考试备考题库及答案解析
- 2026福建龙岩市第一医院医疗辅助岗位招聘4人建设笔试参考题库及答案解析
- 2026广东省惠东县教育局赴高校招聘公办学校教师126人(惠州场)建设笔试备考题库及答案解析
- 2026黑龙江黑河市鸿兴资本运营有限公司招聘工作人员12人建设笔试参考题库及答案解析
- 2026浙江温州市乐清市龙西乡卫生院招聘1人建设考试参考题库及答案解析
- 绍兴市镜湖开发集团有限公司下属企业招聘工作人员5人建设笔试备考试题及答案解析
- 第5课 从小爱劳动 课件(内嵌视频) 2025-2026学年道德与法治三年级下册统编版
- 一年级数学10以内加减法计算专项练习题(每日一练共12份)
- 2026特种作业场内专用机动车辆作业考试题及答案
- (二模)苏北七市2026届高三第二次调研测试生物试卷(含答案)
- TCABEE080-2024零碳建筑测评标准(试行)
- 遗传性高胆红素血症诊疗专家共识(2025年版)解读课件
- 科大讯飞深度研究报告
- (正式版)DB37∕T 4863-2025 《数字经济发展评价指标体系》
- 供方履约评价表(工程施工类)
- 风湿性多肌痛的诊断与治疗课件
- 烤箱能效测试标准
评论
0/150
提交评论