数据结构--员工管理信息系统代码
- 格式:doc
- 大小:23.48 KB
- 文档页数:9
. . 数据结构-员工管理信息系统源程序 #include #include #include #include using namespace std; #define OK 1 #define ERROR 0 #define OVERFLOW -2 typedef int Status; //Status 是函数返回值类型,其值是函数结果状态代码。 #define MAXSIZE 100 //顺序表可能达到的最大长度 typedef struct { //ElemType 为自定义的数据类型,要根据实际情况定义,本例为学生信息:(学号,成绩) int num; string name; string sex; string birth; string edu; string job; string phone; string add; }ElemType;
typedef struct { //定义顺序表类型为List ElemType *elem; int length; }List;
void InitList(List &L) //创建空顺序表 { L.elem=new ElemType[MAXSIZE]; //动态分配空间 L.length=0; }
void ListInput(List &L,int n) //输入顺序表数据 {
int i; cout<<"请输入员工信息"
void ListOutput(List L) //输出顺序表数据 { int i=0;
if (L.length==0) cout<<"空表,无数据输出!"; for(i=0;i
cout<<"("<.elem[i].job<<"," } int LocateElem(List L,int num) //在顺序表里查找某编号员工的信息 { int i; for(i=0;iif(num==L.elem[i].num) return i+1; else return 0; } . . void ListInsert(List &L,ElemType e) //顺序表的插入 { int i; if(L.length==MAXSIZE) cout<<"存储空间已满"; //当前存储空间已满 if(LocateElem(L,e.num)!=0) cout<<"数据已存在,请重新输入"; else { for(i=L.length-1;i>=0;i--) if (e.num L.elem[i+1]=L.elem[i]; //在查找位置的同时元素后移 else break; L.elem[i+1]=e; //将新元素e放入合适的位置 ++L.length; //表长增1 } } void ListDelete(List &L,int bh) // 顺序表的删除 { int i,j; i=LocateElem(L,bh); //查找删除位置 if(i==0) cout<<"找不到此员工相关信息"; else {for(j=i;j<=L.length;j++) L.elem[j-1]=L.elem[j]; //被删除元素之后的元素前移 --L.length; } //表长减1 } void BubbleSort(List &L) { int i,j; ElemType key; for(i=0;i for(j=i+1;j if(L.elem[i].num>L.elem[j].num) { key=L.elem[i]; . . L.elem[i]=L.elem[j]; L.elem[j]=key; } } void ChangeM(List &L) { int i,n,num; cout<<"\t\t\t* 请输入更改的员工编号 *"< cin>>num; cout<<"\t\t\t************************"< cout<<"\t\t\t* *"< cout<<"\t\t\t* [1] 改名字 *"< cout<<"\t\t\t* [2] 改电话 *"< cout<<"\t\t\t* [3] 改性别 *"< cout<<"\t\t\t* [4] 改学历 *"< cout<<"\t\t\t* [5] 改住址 *"< cout<<"\t\t\t* [6] 改编号 *"< cout<<"\t\t\t* [7] 改工作 *"< cout<<"\t\t\t* [8] 改生日 *"< cout<<"\t\t\t************************\n"; cout<<"\t\t\t* 请输入1-8选择修改项 *" if(i switch(n) { case 1: cout<<"\t\t\t 请输入新内容:"< cin>>L.elem[i].name;break; case 2: cout<<"\t\t\t 请输入新内容:"< cin>>L.elem[i].phone;break; case 3: cout<<"\t\t\t 请输入新内容:"< cin>>L.elem[i].sex;break; case 4: cout<<"\t\t\t 请输入新内容:"<. . cin>>L.elem[i].edu;break; case 5: cout<<"\t\t\t 请输入新内容:"< cin>>L.elem[i].add;break; case 6: cout<<"\t\t\t 请输入新内容:"< cin>>L.elem[i].num;break; case 7: cout<<"\t\t\t 请输入新内容:"< cin>>L.elem[i].job;break; case 8: cout<<"\t\t\t 请输入新内容:"< cin>>L.elem[i].birth;break; } else cout<<"未找到要修改的员工信息,请检查是否编号输入有误!\n"; } void menu(void) //主菜单 { system("cls"); cout<<"\n\n"; cout<<"\t\t\t 员工管理系统\n"; cout<<"\t\t\t************************\n"; cout<<"\t\t\t* *\n"; cout<<"\t\t\t* [1] 数 据 输 入 *\n"; cout<<"\t\t\t* [2] 查 询 数 据 *\n"; cout<<"\t\t\t* [3] 更 新 数 据 *\n"; cout<<"\t\t\t* [4] 插 入 数 据 *\n"; cout<<"\t\t\t* [5] 删 除 数 据 *\n"; cout<<"\t\t\t* [6] 员 工 排 序 *\n"; cout<<"\t\t\t* [7]txt文件(员工信息) *\n"; cout<<"\t\t\t* [8] 文 件 导 出 *\n"; cout<<"\t\t\t* [9] 退 出 *\n"; cout<<"\t\t\t* *\n"; cout<<"\t\t\t* *\n"; cout<<"\t\t\t************************\n"; cout<<"\t\t\t 请输入你的选项(1-8):"; } void newFile(List &L){ int i; int num;