版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选优质文档-倾情为你奉上#include <iomanip>#include <iostream>#include <fstream>#include <malloc.h>#include <stdlib.h>#include <string.h>#define NULL 0int const N=20;#define LEN sizeof(struct student)using namespace std;void Menu();void Pass();int n=0; /定义一个全局变量统计职工人数/->定义
2、一个职工信息的结构体struct studentchar nameN; /用来存放姓名char sexN; /用来存放性别char zhiwuN; /用来存放职务char bumenN; / 用来存放所在部门long id; /用来存放编号float paid; /用来存放工资int total; /用来存放总工资struct student *next;/->职工类class Information public: student *creat(); /建立链表 void output(student *head); /显示职工信息 int count(student *head);
3、/定义函数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; /->建立链表信息student *Information:creat(void)/定义一个指向struct student 的结构体指针函数*creat()用来录入职工信息. char chN;n=0; /用来存放职工姓名 p1=p2=(student *)malloc(L
5、EN);/调用malloc()函数用来开辟一个新的存储单元 cout<<" -<< 请建立职工信息表, 在姓名处键以 # 结束输入!>>-"<<endl; cout<<" 姓名:" cin>>ch; head=NULL; /给指针head 赋初值 while (strcmp(ch,"#")!=0) /调用字符比较函数strcmp()用来判断是否继续输入 p1=(student *)malloc(LEN); /调用malloc()函数用来开辟一个新的存储单元 str
6、cpy(p1->name,ch); /将循环结构前面输入的姓名复制到结构体名为p1 的数组name 中 cout<<" 性别:" cin>>p1->sex; cout<<" 编号:" cin>>p1->id; while(p1->id)<0|(p1->id)>) /判断输入的编号是否有效(个) cout<<" 对不起您的输入错误!请重新输入(>0<): " cin>>p1->id; cout<<
7、;" 所在部门:" cin>>p1->bumen; cout<<" 请选择级别:"<<endl; cout<<" 1.经理"<<endl; cout<<" 2.技术人员"<<endl; cout<<" 3.销售人员"<<endl; cout<<" 4.销售经理"<<endl; int xuanze; cin>>xuanze; s
8、witch(xuanze) case 1: float wage1; cout<<"请输入级别:"<<endl; cin>>p1->zhiwu; cout<<"请输入经理的工资:"<<endl; cin>>wage1; p1->paid=wage1; break; case 2: int worktime; int wage2; cout<<"请输入级别:"<<endl; cin>>p1->zhiwu; cou
9、t<<"请输入技术人员的工作时间:"<<endl; cin>>worktime; cout<<"请输入技术人员每小时的工资:"<<endl; cin>>wage2; p1->paid=worktime*wage2; break; case 3: int wage3; double ticheng3; cout<<"请输入级别:"<<endl; cin>>p1->zhiwu; cout<<"请输入
10、当月销售额:"<<endl; cin>>wage3; cout<<"请输入提成比例:"<<endl; cin>>ticheng3; p1->paid=wage3*ticheng3; break; case 4: int wage4; double ticheng4; int gongzi; cout<<"请输入级别:"<<endl; cin>>p1->zhiwu; cout<<"请输入销售经理的固定工资:"
11、<<endl; cin>>gongzi; cout<<"请输入当月销售额:"<<endl; cin>>wage4; cout<<"请输入提成比例:"<<endl; cin>>ticheng4; p1->paid=gongzi+wage4*ticheng4; break; if(n=0)head=p1; /如果是输入第一组职工信息就将指针p1 赋给指针head else p2->next=p1; /否则将p1 赋给p2 所指结构体的next 指针 p
12、2=p1; /将指针p1 赋给指针p2 n+; /将职工人数n 的值加1 cout<<"n 姓名:" cin>>ch; /将输入的姓名存放到字符数组ch 中 p2->next=NULL; /将p2 所指结构体的next 指针重新赋空值 return (head);/将输入的第一组职工信息返回/->定义output()函数将职工的信息从头指针所指内容开始输出void Information:output(student *head) system("cls"); if(head=NULL) cout<<&qu
13、ot; 这是一个空表,请先输入职工信息!n" else cout<<"-n" cout<<" *职工工资信息表*n" cout<<"-n" cout<<"|编 号| |姓 名| |性别| |所在部门| |级别| |工资|n" cout<<"-n" p1=head; /将头指针赋给p do cout<<setw(6)<<p1->id<<setw(10)<<p1->nam
14、e<<setw(10)<<p1->sex<<setw(10)<<p1->bumen<<setw(10)<<p1->zhiwu<<setw(10)<<p1->paid<<endl; cout<<"-n" p1=p1->next; /将下一组职工信息的next 指针赋给p while(p1!=NULL); /若指针p 非空则继续,目的是把所有的职工信息都传给指针p 然后输出./->统计职工人数的函数int Informati
15、on:count(struct student *head) /定义函数count()统计职工总数 if(head=NULL)return(0); /若指针head 为空返回值为0 else return(1+count(head->next); /函数的递归调用/->添加职工的工资的函数student *Information:insert( student *head)/插入新结点定义一个指向struct student 的结构体指针函数*insert()用来添加职工信息. system("cls"); cout<<"t-<<
16、;请输入新增职工成绩信息>>-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<<" 姓名:&qu
17、ot; cin>>p1->name; /将输入的姓名存放到结构体名为p1 的数组name 中 cout<<" 性别:" cin>>p1->sex; cout<<" 所在部门:" cin>>p1->bumen; cout<<" 请选择级别:"<<endl; cout<<" 1.经理"<<endl; cout<<" 2.技术人员"<<endl; cou
18、t<<" 3.销售人员"<<endl; cout<<" 4.销售经理"<<endl; int xuanze; cin>>xuanze; switch(xuanze) case 1:float wage1;cout<<"请输入级别:"<<endl;cin>>p1->zhiwu;cout<<"请输入经理的工资:"<<endl;cin>>wage1;p1->paid=wage1;
19、break; case 2:int worktime;int wage2; cout<<"请输入级别:"<<endl;cin>>p1->zhiwu;cout<<"请输入技术人员的工作时间:"<<endl;cin>>worktime;cout<<"请输入技术人员每小时的工资:"<<endl;cin>>wage2;p1->paid=worktime*wage2;break; case 3: int wage3;doubl
20、e ticheng3;cout<<"请输入级别:"<<endl;cin>>p1->zhiwu;cout<<"请输入当月销售额:"<<endl;cin>>wage3;cout<<"请输入提成比例:"<<endl;cin>>ticheng3;p1->paid=wage3*ticheng3;break; case 4:int wage4;double ticheng4;int gongzi;cout<<&quo
21、t;请输入级别:"<<endl;cin>>p1->zhiwu;cout<<"请输入销售经理的固定工资:"<<endl;cin>>gongzi;cout<<"请输入当月销售额:"<<endl;cin>>wage4;cout<<"请输入提成比例:"<<endl;cin>>ticheng4;p1->paid=gongzi+wage4*ticheng4;break; p2=head; /将头
22、指针赋给p2 if(head=NULL) /若没调用次函数以前的头指针head 为空 head=p1; p1->next=NULL; /则将p1 赋给头指针head 并将p1 所指结构体成员指针next 赋空值 else while(p1->id>p2->id)&&(p2->next!=NULL) p3=p2; /p3 指向原p2 指向的结点 p2=p2->next; /p2 后移一个结点 if(p1->id<=p2->id) if(head=p2) p1->next=head; head=p1; /插入到第一个结点之
23、前 else p3->next=p1; p1->next=p2; /插入到p3 所指结点之后 else p2->next=p1; p1->next=NULL; /插入到尾结点之后 n+; /将职工人数加1 cout<<"t-<< 你输入的职工信息已经成功插入>>-"<<endl; return (head);/->删除职工信息student *Information:cancel(student *head,long id) /定义一个指向structstudent 的结构体指针函数*delete
24、()用来删除考生信息. system("cls"); if(head=NULL) /若调用次函数以前的头指针head 为空 return(head); else p1=head; /否则将头指针赋给p1 while(id!=p1->id&&p1->next!=NULL) /寻找要删除的结点当p1 所指的职工编号不是输入的职工编号并且p1 所指的next 指针不为空 p2=p1; p1=p1->next; /p2 指向原p1 指向的结点p1 后移一个结点 if(id=p1->id) /如果输入的职工编号是p1 所指的职工编号/结点找到后
25、删除 if(p1=head) head=p1->next; /如果head 指针和p1 指针相等则将下一个结点赋给指针head else p2->next=p1->next; /否则将p1 所指结点赋给p2 所指结点将要删除的职工信息跳过去 cout<<" 删除编号为"<<id<<"的职工n" n-; /将职工人数减1 return(head); /将头指针返回/*修改职工数据*/student *Information:modify(student *head,long id) system(&qu
26、ot;cls"); cout<<"t-<< 请输入须修改的职工工资信息>>-n"<<endl; p1=(student *)malloc(LEN); /使p1 指向输入的结点 p1=head; /否则将头指针赋给p1 while(id!=p1->id&&p1->next!=NULL) /寻找结点当p1 所指的职工编号不是输入的职工编号并且p1 所指的next 指针不为空 p1=p1->next; /p2 指向原p1 指向的结点p1 后移一个结点 if(id=p1->id) /如
27、果要查找的职工编号是p1 所指的职工编号 cout<<"你需要修改的职工信息如下:n" cout<<"-n" cout<<"|编 号| |姓 名| |性别| |所属部门| |级别| |工资|n" cout<<"-n" cout<<setw(6)<<p1->id<<setw(10)<<p1->name<<setw(10)<<p1->sex<<setw(10)<&l
28、t;p1->bumen<<setw(10)<<p1->zhiwu<<setw(12)<<p1->paid<<endl; cout<<"-n" cout<<" 编号:" cin>>p1->id; while(p1->id)<0|(p1->id)>) cout<<" 对不起您的输入错误!请重新输入(>0<): " cin>>p1->id; /将输入的编号存
29、放到p1 所指结构体的数组id 中 cout<<" 姓名:" cin>>p1->name; /将输入的姓名存放到结构体名为p1 的数组name 中 cout<<" 性别:" cin>>p1->sex; cout<<" 所属部门:" cin>>p1->bumen; cout<<" 请选择级别:"<<endl; cout<<" 1.经理"<<endl; cout&
30、lt;<" 2.技术人员"<<endl; cout<<" 3.销售人员"<<endl; cout<<" 4.销售经理"<<endl; int xuanze; cin>>xuanze; switch(xuanze) case 1:float wage1;cout<<"请输入级别:"<<endl;cin>>p1->zhiwu;cout<<"请输入经理的工资:"<&
31、lt;endl;cin>>wage1;p1->paid=wage1;break; case 2:int worktime;int wage2;cout<<"请输入级别:"<<endl;cin>>p1->zhiwu;cout<<"请输入技术人员的工作时间:"<<endl;cin>>worktime;cout<<"请输入技术人员每小时的工资:"<<endl;cin>>wage2;p1->paid=wor
32、ktime*wage2;break; case 3: int wage3;double ticheng3;cout<<"请输入级别:"<<endl;cin>>p1->zhiwu;cout<<"请输入当月销售额:"<<endl;cin>>wage3;cout<<"请输入提成比例:"<<endl;cin>>ticheng3;p1->paid=wage3*ticheng3;break; case 4: int wage4;
33、 double ticheng4; int gongzi; cout<<"请输入级别:"<<endl; cin>>p1->zhiwu; cout<<"请输入销售经理的固定工资:"<<endl; cin>>gongzi; cout<<"请输入当月销售额:"<<endl; cin>>wage4; cout<<"请输入提成比例:"<<endl; cin>>ticheng4;
34、 p1->paid=gongzi+wage4*ticheng4; break; elsecout<<" 需要修改的信息中没有编号为"<<id<<"的职工.nn" /没有想要修改的结点信息getchar();return(head);/->查找职工信息student *Information:find(student *head,long id)/定义一个指向struct student 的结构体指针函数*find()用来查找职工信息. system("cls"); if(head=NUL
35、L) /若调用次函数以前的头指针head 为空 cout<<" 这是一个空表,请先输入职工信息!n" return(head); else p1=head; /否则将头指针赋给p1 while(id!=p1->id&&p1->next!=NULL) /寻找结点当p1 所指的职工编号不是输入的职工编号并且p1 所指的next 指针不为空 p1=p1->next; /p2 指向原p1 指向的结点p1 后移一个结点 if(id=p1->id) /如果要查找的职工编号是p1 所指的职工编号 cout<<"-n
36、" cout<<"|编 号| |姓 名| |性别| |所属部门| |级别| |工资|n" cout<<"-n" cout<<setw(6)<<p1->id<<setw(10)<<p1->name<<setw(10)<<p1->sex<<setw(10)<<p1->bumen<<setw(10)<<p1->zhiwu<<setw(12)<<p1->
37、;paid<<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 的结构体指针数组p if(head!
38、=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+) /选择排序法 for(j=k+1
39、;j<m;j+) if(pk->paid<pj->paid) 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->bumen<<setw(10)<<pi->zhiwu<<setw(10)<<pi->
40、paid<<setw(10)<<i+1<<endl; cout<<"-n" /->求各工资的平均值的函数void Information:average(student *head) int k,m; float arg=0; if(head=NULL)/如果头指针是空则继续 cout<<" 这是一个空表,请先输入职工信息!n" else m=count(head); p1=head; for(k=0;k<m;k+) arg+=p1->paid; p1=p1->next;
41、 arg/=m; cout<<" *工资的平均值*n" cout<<"-n" cout<<"tt 工资的平均值: "<<setw(4)<<arg<<"n"<<endl; cout<<"-n" /->保存函数.void Information:save(student *head) system("cls"); ofstream out("data",ios
42、:out); out<<count(head)<<endl; while(head!=NULL) out<<head->name<<"t"<<head->id<<"t"<<"t"<<head->sex<<"t"<<head->bumen<<"t"<<head->zhiwu<<"t"<&l
43、t;head->paid<<"t"<<endl; head=head->next;/->读取文件的信息student *Information:Read() system("cls"); int i=0; p1=p2=( student *)malloc(LEN); head=NULL; ifstream in("data",ios:out); in>>i; if(i=0)cout<<" data 文件中的数据为空,请先输入数据!"<<e
44、ndl; return 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.bumen
45、>>st.zhiwu>>st.paid; strcpy(p1->name,); p1->id=st.id; strcpy(p1->sex,st.sex); strcpy(p1->bumen,st.bumen); strcpy(p1->zhiwu,st.zhiwu); p1->paid=st.paid; if(n=0)head=p1; /如果是输入第一组职工信息就将指针p1赋给指针head else p2->next=p1; /否则将p1 赋给p2 所指结构体的next 指针 p2=p1; /将指针p1 赋给指针p2
46、 n+; /将n 的值加1 /显示读入数据 cout<<" "<<p1->name<<"t"<<p1->id<<" t"<< p1->sex <<" t"<< p1->bumen <<" t"<< p1->zhiwu <<" t"<< p1->paid <<" t"&
47、lt;<endl; cout<<" "<<endl; cout<<" 数据已经成功读取完毕!nn"<<endl; p2->next=NULL; return (head); /->菜单void Menu() Information person; student *head=NULL; int choice; long i; do cout<<"t"<<endl; cout<<"t "<<endl; c
48、out<<"t _ _ _ 欢迎进入职工工资统计管理 _ _ _ "<<endl; cout<<"t "<<endl; cout<<"t"<<endl; cout<<"t"<<endl; cout<<"t 相关操作选项"<<endl; cout<<"t"<<endl; cout<<"t"<<
49、endl; cout<<"t 1. 读取文件信息 "<<endl; cout<<"t "<<endl; cout<<"t 2. 职工数据输入 "<<endl; cout<<"t "<<endl; cout<<"t 3. 显示职工工资 "<<endl; cout<<"t "<<endl; cout<<"t 4. 排序统计工资 "<<endl; cout<<"t "<<endl; cout<<"t 5. 查找职工工资 "<<endl; cout<<"t "<<endl; cout<<"t 6. 增加职工工资 "<<endl; cout<<"t "<<endl;
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 一年级上册语文学习小儿歌合集
- 测量观察数据归档管理制度
- Transformer中的缩放点积注意力极限四则
- 商丘睢阳 2026 年服装厂缝纫工入职规章制度试卷 招聘 44 人
- ASTM D412-24 中文版(详细解读)硫化橡胶拉伸性能测试标准
- 某家具厂安全管理细则
- 建筑施工工地文明施工规则
- 在快节奏中保持清醒在繁琐中保持条理在压力中保持水准-工作状态总结
- AI+法律智能检索深化产业创新发展行动方案
- 撰写线下活动方案策划方法(3篇)
- 《增材制造技术》全套教学课件
- 2026成都盐道街中学高一入学英语分班考试真题含答案
- 港口设施保安培训
- 机械员培训教学课件
- 进出洁净区培训
- 2025至2030中国婴儿汽车安全座椅行业项目调研及市场前景预测评估报告
- 机关事务工作演讲稿
- 2025年设备监理师职业资格考试设备工程项目管理历年参考题库及答案
- 电池均衡原理及讲解
- 日本eju考试物理真题及答案
- 供水管网改造期间的供水保障与服务
评论
0/150
提交评论