简单的职工管理系统方案_第1页
简单的职工管理系统方案_第2页
简单的职工管理系统方案_第3页
简单的职工管理系统方案_第4页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、.#include <string>#include <iostream>#include <fstream>#include <iomanip>#include <memory.h>#include <stdio.h>#include <conio.h>#include <stdlib.h>using namespace std;struct Employee/声明职工的结构作为链表节点。/- 数据域 -string m_Code;string m_Name;unsigned short int

2、m_Year;string m_Sex;string m_Post;string m_Department;unsigned int m_Wage;/链表节点的指针域 -struct Employee* Next;/- 个人习惯:取别名 -typedef struct Employee Node;typedef Node* Link;/- 函数声明 -Link Create(Link Head);void Release(Link Head);Link Add(Link Head);bool Search(Link Head);Link Search_Unique(Link Head);voi

3、d Display_List(Link Head);void Display_Node(Link pNode);Link Modify(Link Head);Link Del(Link Head);void Save_ByFile(Link Head,fstream& ofile);Link Sort(Link Head);/- 函数实现 -Link Create(Link Head)学习好帮手./创建一个带头节点的空链表。Head=(Link)new Node;if(!Head)cout<<" 分配内存失败! "<<endl;return

4、NULL;Head->m_Code=""Head->m_Name=""Head->m_Year=0;Head->m_Sex=""Head->m_Post=""Head->m_Department=""Head->m_Wage=0;Head->Next=NULL;return Head;void Release(Link Head)/释放链表。Link ptr;/ 声明一个操作用的指针。while(Head!=NULL)ptr=Head;Head=H

5、ead->Next;delete ptr;/ 释放节点资源。Link Add(Link Head)/前插法添加数据。Link pNew;/声明一个新节点。char again;string code,name,sex,post,department;unsigned short int year;unsigned int wage;dopNew=(Link)new Node;/数据域。cout<<" 请输入职工代码: "学习好帮手.cin>>code;cout<<endl<<" 请输入职工姓名: "c

6、in>>name;cout<<endl<<" 请输入职工出生年份: "cin>>year;while(cin.fail()cout<<" 请输入正确的年份格式。"<<endl;cin.clear();fflush(stdin);cin>>year;cout<<endl<<" 请输入职工性别: "cin>>sex;cout<<endl<<" 请输入职工职称: "cin>

7、>post;cout<<endl<<" 请输入职工部门: "cin>>department;cout<<endl<<" 请输入职工工资: "cin>>wage;while(cin.fail()cout<<" 请输入正确的工资数据。"<<endl;cin.clear();fflush(stdin);cin>>wage;cout<<endl;pNew->m_Code=code;pNew->m_Name=

8、name;pNew->m_Year=year;pNew->m_Sex=sex;pNew->m_Post=post;pNew->m_Department=department;pNew->m_Wage=wage;/指针域。pNew->Next=Head->Next;Head->Next=pNew;cout<<" 数据添加成功!是否继续添加?(Y/N)"<<endl;cin>>again;while(again='Y'|again='y');return Head

9、;学习好帮手.bool Search(Link Head)/查询同时满足 “姓名 ”和“部门 ”的职工信息。Link ptr;string department;string name;ptr=Head->Next;cout<<" 请输入部门: "cin>>department;cout<<endl<<" 请输入姓名: "cin>>name;cout<<endl<<"-查询结果 -"<<endl;while(ptr)if(ptr-&g

10、t;m_Name=name)&&(ptr->m_Department=department)Display_Node(ptr);/ 打印满足条件的节点。return true;ptr=ptr->Next;/ 查询下一节点。cout<<" 无此职工的信息。 "<<endl;return false;Link Search_Unique_Front(Link Head)/查询满足 “职工代码 “的职工信息(职工代码必需唯一)。Link ptr;string code;ptr=Head;cout<<" 请输

11、入职工代码: "cin>>code;cout<<endl<<"-查询结果 -"<<endl;while(ptr->Next)if(ptr->Next->m_Code=code)/Display_Node(ptr);/ 打印满足条件的节点。return ptr;/ 注意,是返回的查询到的节点的直接前趋节点。ptr->Next=ptr->Next->Next;/查询下一节点。return ptr;学习好帮手.void Display_List(Link Head)Link ptr;pt

12、r=Head->Next;cout<<"=所有职工信息 ="<<endl;while(ptr)Display_Node(ptr);ptr=ptr->Next;void Display_Node(Link pNode)/在标准输出设备上输出。cout<<setw(10)<<left<<pNode->m_Code<<setw(10)<<left<<pNode->m_Name<<setw(10)<<left<<pNode-&g

13、t;m_Year<<setw(10)<<left<<pNode->m_Sex<<setw(10)<<left<<pNode->m_Post<<setw(10)<<left<<pNode->m_Department<<setw(10)<<left<<pNode->m_Wage<<endl;/setw(10) 表示占 10 个字符位置。 Link Modify(Link Head)/ 修改单一个节点。Link ptr;p

14、tr=Search_Unique_Front(Head);string code,name,sex,post,department;unsigned short int year;unsigned int wage;if(ptr->Next)cout<<"- 你现在可以修改此职工的信息了-"<<endl;/数据域。cout<<" 请输入职工代码: "cin>>code;cout<<endl<<" 请输入职工姓名: "cin>>name;cout&

15、lt;<endl<<" 请输入职工出生年份: "cin>>year;学习好帮手.while(cin.fail()cout<<" 请输入正确的年份格式。"<<endl;cin.clear();fflush(stdin);cin>>year;cout<<endl<<" 请输入职工性别: "cin>>sex;cout<<endl<<" 请输入职工职称: "cin>>post;cout&

16、lt;<endl<<" 请输入职工部门: "cin>>department;cout<<endl<<" 请输入职工工资: "cin>>wage;while(cin.fail()cout<<" 请输入正确的工资数据。"<<endl;cin.clear();fflush(stdin);cin>>wage;cout<<endl;ptr->Next->m_Code=code;/ 因 ptr 是前趋节点,所以要用 ptr

17、->Next; ptr->Next->m_Name=name;ptr->Next->m_Year=year;ptr->Next->m_Sex=sex;ptr->Next->m_Post=post;ptr->Next->m_Department=department;ptr->Next->m_Wage=wage;cout<<" 没找到此职工的记录 ,无法修改。 "<<endl; return Head;Link Del(Link Head)Link ptr;Link ptr_

18、front;ptr_front=Search_Unique_Front(Head);ptr=ptr_front->Next;if(ptr)学习好帮手.ptr_front->Next=ptr->Next;delete ptr;/ 删除此节点。cout<<" 没找到此职工的记录 ,无法删除。 "<<endl; return Head;void Save_ByFile(Link Head,fstream& ofile)Link pNode;pNode=Head->Next;ofile.clear();/ 清除文件结束状态。w

19、hile(pNode)ofile<<setw(10)<<left<<pNode->m_Code<<setw(10)<<left<<pNode->m_Name<<setw(10)<<left<<pNode->m_Year<<setw(10)<<left<<pNode->m_Sex<<setw(10)<<left<<pNode->m_Post<<setw(10)<<l

20、eft<<pNode->m_Department<<setw(10)<<left<<pNode->m_Wage<<endl;/setw(10)表示占 10 个字符位置。pNode=pNode->Next;cout<<" 数据文件保存成功! "<<endl;Link Sort(Link Head)/我创建的是带头节点的链表。用直接插入法。if(Head->Next=NULL)|(Head->Next->Next=NULL)/ 此步条件判断非常有价值。cout

21、<<" 数据节点数少于 2 个,不用排序! "<<endl; return Head;/- 第二步;Link ptr;Link ptr_F;Link ptr_N;ptr=Head->Next->Next;ptr_F=Head;学习好帮手.Head->Next->Next=NULL;/到此,分成了两个链表。/第三步。while(ptr)ptr_N=ptr->Next;ptr_F=Head;/ptr_F的归位。while(ptr_F->Next)if(ptr->m_Wage>ptr_F->Next-&

22、gt;m_Wage)ptr->Next=ptr_F->Next;ptr_F->Next=ptr;break;/ifelseptr_F=ptr_F->Next;/while(ptr_F->Next)if(ptr_F->Next=NULL)ptr->Next=ptr_F->Next;ptr_F->Next=ptr;/ 表示插到有序链表的最后面了。ptr=ptr_N;/ 归位,准备下一次排序。/while(ptr)cout<<" 从高到低,排序成功! "<<endl;return Head;int ma

23、in()Link Head=0;Head=Create(Head);fstream iofile;iofile.open("d:iofile.txt",ios_base:in|ios_base:out|ios_base:app);/文件以三种方式打开。if(!iofile)学习好帮手.cout<<" 打开文件失败! "<<endl;return -1;int menu;while(1)cout<<"*"<<endl;cout<<"*=菜单选顶=*"<<endl; cout<<"*=*" <<endl;cout<<"* 1. 注册职工 2.修改信息 3.删除信息 4.信息查询 *"<<endl; cout<<"* 5. 保存文件 6.工资排行 7.信息显示 0.退出系统 *&qu

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论