




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精品资料 struct student char nameN; char sexN; long id; float paid3; int total; class Information public: Information() ; Information() ; student *creat(); / 构造函数 . / 析构函数 . / 建立链表 #include #include #include #include #include #include using namespace std; #define NULL 0 #define LEN sizeof(struct student
2、) int const N=20; void Menu(); void Pass(); int n=0; / 定义一个全局变量统计职工人数 / 定义一个职工信息的结构体 / 用来存放姓名 / 用来存放性别 / 用来存放编号 / 用来存放工资 / 用来存放总工资 struct student *next; ; / 职工类 可修改 / void output(student *head); int count(student *head); student *insert(student*head); student *cancel(student *head,long id); student
3、*find(student *head,long id); student *modify(student *head,long id); void paixu(student *head); 列并输出 void average(student *head); void save(student *head); student *Read(); private: / 显示职工信息 / 定义函数 count() 统计职工总数 指针函数 *insert() 用来添加职工信息 . / 指针函数 *cancel() 用来删除职工信息 . / 指针函数 *find() 用来查找职工信息 . / 指针函数
4、 *modife() 用来修改职工的信息 . / 定义 paixu() 函数将职工的总额从大到小排 / 定义职工工资平均值的函数 / 保存文件信息 / 读取文件信息 student *p1,*p2,*p3,*head,st; ; Information:Information() cout * cout n; cout *nn; * Information:Information() cout ooooooooooooooooooooooooooooooooooooooo n; cout n; cout 本 系 统 管 理 员 n; cout n; cout n; cout n; cout n
5、; cout n; cout 欢 迎 下 次 使 用 n; cout n; cout n; cout 再 见 n; cout n; cout ooooooooooooooooooooooooooooooooooooooo n; 建立链表信息 student *Information:creat(void) / 定义一个指向 struct student char chN;n=0; p1=p2=(student *)malloc(LEN);/ / cout endl; coutch; head=NULL; / 给指针 head while (strcmp(ch,#)!=0) / 调用字符比较函数
6、 strcmp() p1=(student *)malloc(LEN); strcpy(p1-name,ch); p1 的数组 name 中 coutp1-sex; coutp1-id; while(p1-id)id)100000) coutp1-id; coutp1-paid0; while(p1-paid0)paid0)100000) (=0 =100000) coutp1-paid0; coutp1-paid1; while(p1-paid1)paid1)100000) (=0 =100000) coutp1-paid1; coutp1-paid2; 的结构体指针函数 *creat()
7、用来录入职工信息 . / 用来存放职工姓名 调用 malloc() 函数用来开辟一个新的存储单元 员工 信 息 表 , 在 姓名 处 键 以 # 结 束 赋初值 用来判断是否继续输入 / 调用 malloc() 函数用来开辟一个新的存储单元 / 将循环结构前面输入的姓名复制到结构体名为 / 判断输入的编号是否有效 (100000 个 ) (000paid2)paid2)100000) / 判断输 入的分数 是否有 效 (=0 =100000) cout0p1-paid2; p1-total=p1-paid0+p1-paid1+p1-paid2; / 计算总额 if(n=0)head=p1; /
8、 如果是输入第一组职工信息就将指针 p1 赋给指针 head else p2-next=p1;/ 否则将 p1 赋给 p2 所指结构体的 next 指针 p2=p1; / 将指针 p1 赋给指针 p2 n+; / 将职工人数 n 的值加 1 coutch; / 将输入的姓名存放到字符数组 ch 中 p2-next=NULL; / 将 p2 所指结构体的 next 指针重新赋空值 return (head);/将输入的第一组职工信息返回 / 定义 output() 函数将职工的信息从头指针所指内容开始输出 void Information:output(student *head) system
9、(cls); if(head=NULL) cout这是一个空表 ,请先输入员工信息 !n; else coutn; cout * 职工工资信息表 *n; coutn; cout| 编 号| | 姓 名| | 性别 | | 基本工资 | | 加班工资 | | 其他奖金 | | 总额 |n; coutn; p1=head; / 将头指针赋给 p do coutsetw(6)id setw(10)name setw(10)sex setw(10)paid0 setw(10)paid1 setw(12)paid2 setw(12)totalendl; coutnext; / 将下一组职工信息的 nex
10、t 指针赋给 p while(p1!=NULL); / 若指针 p 非空则继续 , 目的是把所有的职工信息都传给指针p 然 后输出 . / 统计职工人数的函数 int Information:count(struct student *head) if(head=NULL)return(0); else return(1+count(head-next); / 定义函数 count() 统计职工总数 / 若指针 head 为空返回值为 0 / 函数的递归调用 / 添加职工的成绩的函数 student *Information:insert( student *head) / 插入新结点定义一个
11、指向 struct student 的结构体指针函数 *insert() 用来添加职工信 息. system(cls); couttnendl; p1=(student *)malloc(LEN); / 使 p1 指向插入的新结点 coutp1-id; while(p1-id)id)100000) cout0p1-id; / 将输入的编号存放到 p1 所指结构体的数组 id 中 coutp1-name; / 将输入的姓名存放到结构体名为 p1 的数组 name 中 coutp1-sex; coutp1-paid0; while(p1-paid0)paid0)100000) cout0p1-pa
12、id0; / 将输入的基本工资存放到 p1 所指结构体的数组 paid 中 coutp1-paid1; while(p1-paid1)paid1)100000) cout0p1-paid1; / 将输入的加班工资存放到 p1 所指结构体的数组 paid 中 coutp1-paid2; while(p1-paid2)paid2)100000) cout0p1-paid2; / 将输入的其他奖金存放到 p1 所指结构体的数组 paid 中 p1-total=p1-paid0+p1-paid1+p1-paid2;/ 计算总分 p2=head; / 将头指针赋给 p2 if(head=NULL) /
13、若没调用次函数以前的头指针 head 为空 head=p1;p1-next=NULL; / 则将 p1 赋给头指针 head 并将 p1 所指结构体成员指针 next 赋空值 else while(p1-idp2-id) /p3 指向原 p2 指向的结点 p2=p2-next; /p2 后移一个结点 if(p1-idid) if(head=p2) p1-next=head; head=p1; / 插入到第一个结点之前 else p3-next=p1; p1-next=p2; / 插入到 p3 所指结点之后 else p2-next=p1; p1-next=NULL; / 插入到尾结点之后 n+
14、; / 将职工人数加 1 coutt 删除职工信息 student *Information:cancel(student *head,long id) / 定 义 一 个 指 向 struct student 的结构体指针函数 *delete() 用来删除考生信息 . system(cls); if(head=NULL) / 若调用次函数以前的头指针 head 为空 return(head); else p1=head; / 否则将头指针赋给 p1 while(id!=p1-id p1=p1-next; /p2 指向原 p1 指向的结点 p1 后移一个结点 if(id=p1-id) / 如果
15、输入的职工编号是 p1 所指的职工编号 / 结点找到后删除 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(cls); couttnid /
16、p2 指向原 p1 指向的结点 p1 后移一个结点 if(id=p1-id) / 如果要查找的职工编号是 p1 所指的职工编号 cout 你需要修改的员工信息如下 :n; coutn; cout| 编 号| |姓 名|性别| |基本工资 | |加班工资| |其他奖金 | | 总额 |n; coutn; coutsetw(6)id setw(10)name setw(10)sex setw(10)paid0 setw(10)paid1 setw(12)paid2 setw(12)totalendl; coutn; coutp1-id; while(p1-id)id)100000) cout0p1
17、-id; / 将输入的编号存放到 p1 所指结构体的数组 id 中 coutp1-name; / 将输入的姓名存放到结构体名为 p1 的数组 name 中 coutp1-sex; coutp1-paid0; while(p1-paid0)paid0)100000) cout0p1-paid0; / 将输入的基本工资存放到 p1 所指结构体的数组 paid 中 coutp1-paid1; while(p1-paid1)paid1)100000) cout0p1-paid1; / 将输入的加班工资存放到 p1 所指结构体的数组 paid 中 coutp1-paid2; while(p1-paid2
18、)paid2)100000) cout0p1-paid2; / 将输入的其他奖金存放到 p1 所指结构体的数组 paid 中 p1-total=p1-paid0+p1-paid1+p1-paid2; / 计算总分 else cout 需要修改的信息中没有编号为 id 查找职工信息 student *Information:find(student *head,long id) / 定义一个指向 struct student 的结构体指针函数 *find() 用来查找职工信息 . system(cls); if(head=NULL) / 若调用次函数以前的头指针 head 为空 coutid /
19、p2 指向原 p1 指向的结点 p1 后移一个结点 if(id=p1-id) / 如果要查找的职工编号是 p1 所指的职工编号 coutn; cout| 编 号| | 姓 名| 性别 | 基本工资 | | 加班工资 | | 其他奖金 | | 总额 |n; coutn; coutsetw(6)id setw(10)name setw(10)sex setw(10)paid0 setw(10)paid1 setw(12)paid2 setw(12)totalendl; coutn; else cout 信息中没有编号为 id 的员工 .n; / 结点没找到 return(head); / 定义 p
20、aixu() 函数将职工的工资总额从大到小排列并输出 void Information:paixu(student *head) system(cls); int i,k,m=0,j; student *pN;/定义一个指向 struct student 的结构体指针数组 p if(head!=NULL)/ 如果头指针是空则继续 m=count(head); coutn; cout * 员工工资统计表 *n; coutn; cout| 编号 | | 姓名 | | 性别 | | 基本工资 | | 加班工资 | | 其他奖金 | | 总 额| | 名次 |n; coutn; p1=head; fo
21、r(k=0;knext; for(k=0;km-1;k+) /选择排序法 for(j=k+1;jtotaltotal) p2=pk; pk=pj; pj=p2; / 从大到小排列的指针 for(i=0;im;i+) coutsetw(6)id setw(8)name setw(9)sex setw(10)paid0 setw(10)paid1 setw(10)paid2 setw(10)total setw(10)i+1endl; cout 求各工资的平均值的函数 void Information:average(student *head) int k,m; float arg1=0,arg
22、2=0,arg3=0; if(head=NULL)/ 如果头指针是空则继续 cout 这是一个空表 ,请先输入员工信息 !n; else m=count(head); p1=head; for(k=0;kpaid0; arg2+=p1-paid1; arg3+=p1-paid2; p1=p1-next; arg1/=m;arg2/=m;arg3/=m; cout * 各项工资的平均值 *n; coutn; couttt 基本工资的平均值 : setw(4)arg1 ntt 加班工资的平均值 : setw(4)arg2 ntt 奖金的平均值 : setw(4)arg3n; cout 保存函数 .
23、 void Information:save(student *head) system(cls); ofstream out(data.txt,ios:out); outcount(head)endl; while(head!=NULL) outnamet idtt sext paid0t paid1t paid2t totalnext; / 读取文件的信息 student *Information:Read() system(cls); int i=0; p1=p2=( student *)malloc(LEN); head=NULL; ifstream in(data.txt,ios:i
24、n); ini; if(i=0)cout data 文件中的数据为空 ,请先输入数据 !endl; return 0; else coutn 原文件已保存的信息如下 :n; COUt endl; COut| 姓 名| 编 号 | 性别 | 基本工资 | 加班工资 | 其他奖金 | | 总额 |n; COut 0;i-) p1=(student *)mallOC(LEN); st.idst.sex st.paid0st.paid1st.paid2st.tOtal; strCpy(p1-name,); p1-id=st.id; strCpy(p1-sex,st.se
25、x); 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 指针 p2=p1; / 将指针 p1 赋给指针 p2 n+; / 将 n 的值加 1 / 显示读入数据 cout namet id t sex t paid0 t paid1 t paid2 t totalendl; COUt endl; COut 数据已经
26、成功读取完毕 !nnnext=NULL; in.ClOse(); return (head); / 菜单 vOid Menu() InfOrmatiOn persOn; student *head=NULL; int ChOiCe; lOng i; head=persOn.Read(); dO COutt endl; COutt endl; COutt _ _ _ 欢迎进入员工信息统计管理 _ _ _ endl; COutt endl; COutt endl; COutt endl; COutt 相关操作选项 endl; COutt endl; COutt zzzzzzzzzzzzzzzzzz
27、zzzzzzz endl; COutt 探e ndl; COutt endl; COutt 1. 员工数据输入 endl; COutt endl; coutt 2. 显示员工工资 海endl; coutt endl; coutt 3. 排序统计工资 endl; coutt endl; coutt 4. 查找员工工资 endl; coutt endl; coutt 5. 增加员工工资 endl; coutt endl; coutt 6. 删除员工工资 endl; coutt endl; coutt 7. 修改员工信息 endl; coutt endl; coutt 8. 成功保存信息 endl;
28、 coutt endl; coutt 9. 安全退出系统 endl; coutt endl; coutt nendl; coutchoice; while(choice9) coutchoice; /head=person.Read(); switch(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(); couti; while(i100000) couti; perso
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025内蒙古自治区新劳动合同样本
- 2025包装箱订购合同范本
- 2025房屋租赁信托合同协议书范本
- 2025年间歇式空气中有机污染物自动分析仪项目建议书
- 2025年高导热石墨膜项目合作计划书
- 2025年钢材:一级钢项目建议书
- 2025年小型高效沼气装置项目建议书
- 引水陂施工方案
- 大坝机械施工方案
- 桥梁截流施工方案
- 校园安全管理的问题及对策研究
- PA66ROHS无卤sgs报告环保报告
- 《送元二使安西》优秀课件
- 中国与俄罗斯渔业合作的潜力分析
- 2023年广东省高中学生化学竞赛试题与标准答案正式题(word可编辑版)
- 汽车轮胎教案
- 公司应急组织体系
- 局部解剖学:第八章 血 管
- 电子政务与电子商务的关系探讨
- 厨师菜品考核评分表201921
- 人工湿地设计方案综述
评论
0/150
提交评论