员工管理系统数据结构.docx
《员工管理系统数据结构.docx》由会员分享,可在线阅读,更多相关《员工管理系统数据结构.docx(19页珍藏版)》请在冰豆网上搜索。
员工管理系统数据结构
学号09710219
数据结构课程设计
设计说明书
员工管理系统
起止日期:
2012年1月2日至2012年1月6日
学生姓名
孙久岩
班级
09计算机2班
成绩
指导教师(签字)
电子与信息工程系
2012年1月4日
天津城市建设学院
课程设计任务书
2010—2011学年第1学期
电子与信息工程系计算机专业09级二班级
课程设计名称:
数据结构课程设计
设计题目:
员工管理系统
完成期限:
自2012年1月2日至2012年1月6日共1周
设计依据、要求及主要内容(可另加附页):
一、设计目的
熟悉各种数据结构和运算,会使用数据结构的基本操作解决一些实际问题。
二、设计要求
(1)重视课程设计环节,用严谨、科学和踏实的工作态度对待课程设计的每一项任务;
(2)按照课程设计的题目要求,独立地完成各项任务,严禁抄袭;凡发现抄袭,抄袭者与被抄袭者皆以零分计入本课程设计成绩。
凡发现实验报告或源程序雷同,涉及的全部人员皆以零分计入本课程设计成绩;
(3)学生在接受设计任务后,首先要按设计任务书的要求编写设计进程表;
(4)认真编写课程设计报告。
三、设计内容
员工管理系统:
1)问题描述
每个员工的信息包括:
编号、姓名、性别、出生年月、学历、职务、电话、住址等。
系统能够完成员工信息的查询、更新、插入、删除、排序等功能。
2)基本要求
(1)排序:
按不同关键字,对所有员工的信息进行排序。
(2)查询:
按特定条件查找员工。
(3)更新:
按编号对某个员工的某项信息进行修改。
(4)插入:
加入新员工的信息。
(5)删除:
按编号删除已离职的员工的信息。
四、参考文献
1.王红梅.数据结构.清华大学出版社
2.王红梅.数据结构学习辅导与实验指导.清华大学出版社
3.严蔚敏,吴伟民.数据结构(C语言版).清华大学出版社
五.主要内容:
1.系统流程图
2.源代码:
#include
#include
#include//清屏函数头文件
#include
structStuff
{
charnumber[10];//员工编号
charname[10];//员工姓名
charsex[8];//员工性别
charborth[10];//员工生日
chardegree[20];//员工学历
charbusiness[20];//员工职务
charphone[15];//员工电话
charplace[50];//员工住址
charcon[50];//判断关键字专用
structStuff*next;
};
charMenu(void);//菜单显示
structStuff*App(structStuff*head);//添加
voidSort(structStuff*head);//排序
structStuff*Ser(structStuff*head);//查找
voidChn(structStuff*head,charn[10]);//更改
voidScpy(char*p,char*q);//排序中用于交换员工信息
structStuff*Del(structStuff*head,charn[10]);//删除
intSel(charch,structStuff*p,structStuff*q);//判断排序及关键字专用函数
voidPrf(structStuff*head);//输出
voidFre(structStuff*head);//释放
inti=1;//定义全局变量,实现实时员工人数统计
intmain(void)
{
charn[10];
structStuff*head=NULL;//链表头指针定义
while
(1)
{
switch(Menu())
{
case'1':
printf("请输入员工信息,直接输入'#'结束\n");
head=App(head);
break;
case'2':
Sort(head);
break;
case'3':
head=Ser(head);
break;
case'4':
printf("员工信息如下:
\n");
Prf(head);
break;
case'5':
printf("请输入员工编号:
");
scanf("%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);
return0;
}
//菜单函数
charMenu(void)
{
charch;
printf("------------请选择-----------\n");
printf("1.添加员工信息\n2.员工信息排序\n3.查找员工信息\n4.输出员工信息\n5.更改员工信息\n6.删除员工信息\n0.退出\n-----------------------------\n");
scanf("%c",&ch);
returnch;
}
//添加成员函数
//输入参数:
链表头指针
//返回参数:
链表头指针
structStuff*App(structStuff*head)
{
structStuff*p=NULL,*q=head;
while(i)
{
p=(structStuff*)malloc(sizeof(structStuff));//申请结构体空间
if(p==NULL)
{
printf("内存不够!
\n");
exit(0);
}
p->next=NULL;//指针域为空
printf("请输入第%d名员工:
\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->con[0]='\0';//防止后面判断出现随机值
if(head==NULL)
head=p;
else
{
while(q->next!
=NULL)//防止结束后再次输入时出现问题
q=q->next;
q->next=p;
}
q=p;//每次都加在链表尾
}
}
returnhead;
}
//排序函数
//输入参数:
头指针
voidSort(structStuff*head)
{
charch;
structStuff*p,*q,*r;
while
(1)
{
printf("请选择排序条件:
1.编号2.姓名3.性别4.出生年月5.学历6.职务7.电话8.地址0.退出\n");
scanf("%c",&ch);
if(ch=='0')
break;
if(ch<'1'||ch>'8')
{
printf("输入错误,请重新输入!
\n");
continue;
}
p=head;
while(p->next!
=NULL)//选择排序
{
q=p->next;
r=p;
while(q!
=NULL)
{
if(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;
}
Prf(head);//输出
}
}
//交换函数
voidScpy(char*p,char*q)
{
charc[50];
strcpy(c,p);
strcpy(p,q);
strcpy(q,c);
}
//判断函数
//输出参数:
1为真,0为假
intSel(charch,structStuff*p,structStuff*q)
{
switch(ch)//实现各个关键字查找
{
case'1':
returnstrcmp(q->number,p->number)<0||strcmp(q->con,p->number)==0;//排序条件及查找条件
case'2':
returnstrcmp(q->name,p->name)<0||strcmp(q->con,p->name)==0;
case'3':
returnstrcmp(q->sex,p->sex)<0||strcmp(q->con,p->sex)==0;
case'4':
returnstrcmp(q->borth,p->borth)<0||strcmp(q->con,p->borth)==0;
case'5':
returnstrcmp(q->degree,p->degree)<0||strcmp(q->con,p->degree)==0;
case'6':
returnstrcmp(q->business,p->business)<0||strcmp(q->con,p->business)==0;
case'7':
returnstrcmp(q->phone,p->phone)<0||strcmp(q->con,p->phone)==0;
case'8':
returnstrcmp(q->place,p->place)<0||strcmp(q->con,p->place)==0;
default:
exit(0);
}
}
//查找函数
structStuff*Ser(structStuff*head)
{
structStuff*p=NULL,*q,a={"\0","\0","\0","\0","\0","\0","\0","\0"};//防止判断时错误
intflag;//查找判断
charch,sh;
q=&a;
while
(1)
{
printf("请输入要查找的条件:
1.编号2.姓名3.性别4.出生年月5.学历6.职务7.电话8.住址0.退出\n");
scanf("%c",&ch);
if(ch=='0')
break;
if(ch<'1'||ch>'8')
{
printf("输入错误,请重新输入!
\n");
continue;
}
fflush(stdin);
printf("请输入:
");
gets(q->con);
p=head;//指向表头
flag=0;
while(p!
=NULL)
{
if(Sel(ch,p,q))
{
printf("员工信息如下:
\n");
printf("编号|姓名|性别|出生年月|学历|职务|电话|住址\n%s%s%s%s%s%s%s%s\n"
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);//调用更改函数
elseif(sh=='2')
head=Del(head,p->number);//调用删除函数,得到的head必须return
flag=1;
break;
}
p=p->next;
}
if(flag==0)
printf("没有找到该员工信息!
\n");
}
returnhead;
}
//更改函数
//输入参数:
n[10]为员工编号
voidChn(structStuff*head,charn[10])
{
structStuff*p=head;
intflag=0;
if(head==NULL)
printf("未找到员工信息!
\n");
else
{
while(p!
=NULL)
{
if(!
strcmp(p->number,n))
{
printf("请输入新的信息:
\n编号|姓名|性别|出生年月|学历|职务|电话|住址\n");
scanf("%s%s%s%s%s%s%s%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为员工编号
//输出参数:
头指针
structStuff*Del(structStuff*head,charn[10])
{
structStuff*p,*pr;
intflag;
flag=0;
p=head,pr=head;
if(head==NULL)
printf("未找到员工信息!
\n");
else
{
while(strcmp(p->number,n)&&p->next!
=NULL)
{
pr=p;
p=p->next;
}
if(!
strcmp(p->number,n))
{
if(p==head)
head=p->next;
else
pr->next=p->next;
free(p);
printf("删除成功!
\n");
i--;
}
else
printf("未找到员工信息!
\n");
}
Prf(head);
returnhead;
}
//输出函数
voidPrf(structStuff*head)
{
structStuff*p=head;
inti=1;
while(p!
=NULL)
{
printf("%d.%s%s%s%s%s%s%s%s\n"
i++,p->number,p->name,p->sex,p->borth,p->degree,p->business,p->phone,p->place);
p=p->next;
}
}
//释放函数
voidFre(structStuff*head)
{
structStuff*p;
while(head!
=NULL)
{
p=head;
head=head->next;
free(p);
}
}
六.实验界面截图:
(1)管理界面
(2)输入界面
(3)修改信息界面
(4)查询信息界面
(5)删除信息界面