《c语言课程设计超市员工管理系统.pdf》由会员分享,可在线阅读,更多相关《c语言课程设计超市员工管理系统.pdf(9页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、cheng#include#include#include/清屏函数头文件#include struct Stuffchar number10;/员工编号char name10;/员工姓名char sex8;/员工性别char borth10;/员工生日char degree20;/员工学历char business20;/员工职务char phone15;/员工电话char place50;/员工住址char con50;/判断关键字专用struct Stuff*next;char Menu(void);/菜单显示struct Stuff*App(struct Stuff*head);/添加
2、void Sort(struct Stuff*head);/排序struct Stuff*Ser(struct Stuff*head);/查找void Chn(struct Stuff*head,char n10);/更改void Scpy(char*p,char*q);/排序中用于交换员工信息struct Stuff*Del(struct Stuff*head,char n10);/删除int Sel(char ch,struct Stuff*p,struct Stuff*q);/判断排序及关键字专用函数void Prf(struct Stuff*head);/输出void Fre(stru
3、ct Stuff*head);/释放int i=1;/定义全局变量,实现实时员工人数统计int main(void)char n10;struct Stuff*head=NULL;/链表头指针定义while(1)switch(Menu()case 1:printf(请输入员工信息,直接输入#结束n);head=App(head);break;case 2:chengchengSort(head);break;case 3:head=Ser(head);break;case 4:printf(员工信息如下:n);Prf(head);break;case 5:printf(请输入员工编号:);sc
4、anf(%s,n);Chn(head,n);break;case 6:printf(请输入员工编号:);scanf(%s,n);head=Del(head,n);break;case 0:printf(欢迎下次光临,88!n);exit(0);default:printf(输入错误,请重新输入!n);fflush(stdin);/清楚缓冲区printf(按任意键继续);getchar();system(cls);/清屏效果Fre(head);return 0;/菜单函数char Menu(void)char ch;printf(-请选择-n);printf(1.添加员工信息n2.员工信息排序n
5、3.查找员工信息n4.输出员工信息n5.更改员工信息n6.删除员工信息n0.退出n-n);scanf(%c,&ch);return ch;chengcheng/添加成员函数/输入参数:链表头指针/返回参数:链表头指针struct Stuff*App(struct Stuff*head)struct Stuff*p=NULL,*q=head;while(i)p=(struct Stuff*)malloc(sizeof(struct Stuff);/申请结构体空间if(p=NULL)printf(内存不够!n);exit(0);p-next=NULL;/指针域为空printf(请输入第%d 名员工
6、:n,i);printf(编号|姓名|性别|出生年月|学历|职务|电话|住址:n);fflush(stdin);scanf(%s,p-number);if(!strcmp(p-number,#)free(p);/释放不需要的结构体内存break;else+i;scanf(%s%s%s%s%s%s%s,p-name,p-sex,p-borth,p-degree,p-business,p-phone,p-place);p-con0=0;/防止后面判断出现随机值if(head=NULL)head=p;elsewhile(q-next!=NULL)/防止结束后再次输入时出现问题q=q-next;q-n
7、ext=p;q=p;/每次都加在链表尾chengchengreturn head;/排序函数/输入参数:头指针void Sort(struct Stuff*head)char ch;struct Stuff*p,*q,*r;while(1)printf(请选择排序条件:1.编号2.姓名3.性别4.出生年月5.学历6.职务7.电话8.地址0.退出n);scanf(%c,&ch);if(ch=0)break;if(ch8)printf(输入错误,请重新输入!n);continue;p=head;while(p-next!=NULL)/选择排序q=p-next;r=p;while(q!=NULL)i
8、f(Sel(ch,r,q)/调用判断函数r=q;q=q-next;if(r!=p)/交换内容Scpy(r-number,p-number);Scpy(r-name,p-name);Scpy(r-sex,p-sex);Scpy(r-borth,p-borth);Scpy(r-degree,p-degree);Scpy(r-business,p-business);Scpy(r-phone,p-phone);Scpy(r-place,p-place);p=p-next;chengchengPrf(head);/输出/交换函数void Scpy(char*p,char*q)char c50;strc
9、py(c,p);strcpy(p,q);strcpy(q,c);/判断函数/输出参数:1 为真,0 为假int Sel(char ch,struct Stuff*p,struct Stuff*q)switch(ch)/实现各个关键字查找case 1:return strcmp(q-number,p-number)con,p-number)=0;/排序条件及查找条件case 2:return strcmp(q-name,p-name)con,p-name)=0;case 3:return strcmp(q-sex,p-sex)con,p-sex)=0;case 4:return strcmp(q
10、-borth,p-borth)con,p-borth)=0;case 5:return strcmp(q-degree,p-degree)con,p-degree)=0;case 6:return strcmp(q-business,p-business)con,p-business)=0;case 7:return strcmp(q-phone,p-phone)con,p-phone)=0;case 8:return strcmp(q-place,p-place)con,p-place)=0;default:exit(0);/查找函数struct Stuff*Ser(struct Stuff
11、*head)chengchengstruct Stuff*p=NULL,*q,a=0,0,0,0,0,0,0,0;/防止判断时错误int flag;/查找判断char ch,sh;q=&a;while(1)printf(请输入要查找的条件:1.编号 2.姓名 3.性别 4.出生年月 5.学历 6.职务 7.电话 8.住址0.退出n);scanf(%c,&ch);if(ch=0)break;if(ch8)printf(输入错误,请重新输入!n);continue;fflush(stdin);printf(请输入:);gets(q-con);p=head;/指向表头flag=0;while(p!=
12、NULL)if(Sel(ch,p,q)printf(员工信息如下:n);printf(编 号|姓 名|性 别|出 生 年 月|学 历|职 务|电 话|住 址n%s%s%s%s%s%s%s%sn,p-number,p-name,p-sex,p-borth,p-degree,p-business,p-phone,p-place);printf(是否需要:1.更改 2.删除 3.继续n);scanf(%c,&sh);if(sh=1)Chn(head,p-number);/调用更改函数else if(sh=2)head=Del(head,p-number);/调用删除函数,得到的 head 必须 re
13、turnflag=1;break;p=p-next;if(flag=0)printf(没有找到该员工信息!n);chengchengreturn head;/更改函数/输入参数:n10为员工编号void Chn(struct Stuff*head,char n10)struct Stuff*p=head;int flag=0;if(head=NULL)printf(未找到员工信息!n);elsewhile(p!=NULL)if(!strcmp(p-number,n)printf(请输入新的信息:n 编号|姓名|性别|出生年月|学历|职务|电话|住址n);scanf(%s%s%s%s%s%s%s
14、%s,p-number,p-name,p-sex,p-borth,p-degree,p-business,p-phone,p-place);printf(员工信息如下:n);flag+;break;p=p-next;if(flag=0)printf(未找到该员工信息!n);Prf(head);/删除函数/输入参数:n为员工编号/输出参数:头指针struct Stuff*Del(struct Stuff*head,char n10)struct Stuff*p,*pr;int flag;flag=0;p=head,pr=head;if(head=NULL)chengchengprintf(未找到
15、员工信息!n);elsewhile(strcmp(p-number,n)&p-next!=NULL)pr=p;p=p-next;if(!strcmp(p-number,n)if(p=head)head=p-next;elsepr-next=p-next;free(p);printf(删除成功!n);i-;elseprintf(未找到员工信息!n);Prf(head);return head;/输出函数void Prf(struct Stuff*head)struct Stuff*p=head;int i=1;while(p!=NULL)printf(%d.%s%s%s%s%s%s%s%sn,i+,p-number,p-name,p-sex,p-borth,p-degree,p-business,p-phone,p-place);p=p-next;/释放函数void Fre(struct Stuff*head)struct Stuff*p;while(head!=NULL)chengchengp=head;head=head-next;free(p);cheng