C语言+数据结构学期课程设计《员工管理系统》
立即下载
资源介绍:
关于一个员工管理系统的开发,详细描述了如何构建一个具备基本功能的员工信息管理软件。系统的核心目标是有效地组织和维护员工的个人及工作相关数据,确保数据的准确性和易于访问性。
系统的主要特点包括:
员工信息管理:每个员工的记录包含编号、姓名、性别、出生日期、学历、职务、电话号码和住址。
数据持久化:系统能够将员工数据保存到文件中,以便在程序关闭后数据不会丢失,并且在下次启动时能从文件中恢复这些数据。
数据检索:支持按ID或姓名查找员工的具体信息。
数据更新:允许管理员根据员工的编号修改其个人信息。
数据录入:具备添加新员工信息的功能。
数据移除:可以按员工编号删除不再在职的员工记录。
数据排序:能够按照员工的ID、姓名或出生日期对所有员工信息进行排序。
数据展示:可以列出所有员工的信息,或者展示排序后的员工列表。
在技术实现上,文档采用了C语言编程,并利用了动态顺序表作为存储结构,这使得数据的增删改查更加高效。此外,还设计了一系列函数来实现上述各项功能
#define _CRT_SECURE_NO_WARNINGS 1
#include "SeqList.h"
#include "employee.h"
// 系统主菜单
void menu()
{
printf("*****************************\n");
printf("******员工信息管理系统*******\n");
printf("*1. 输入员工信息\n");
printf("*2. 查找员工\n");
printf("*3. 修改员工\n");
printf("*4. 插入员工\n");
printf("*5. 删除员工\n");
printf("*6. 排序输出员工信息\n");
printf("*7. 查看所有员工信息\n");
printf("*8. 退出系统\n");
printf("*****************************\n");
}
// 导入数据
// 加载上一次的数据
void LoadEmployee(SL* employees)
{
FILE* pf = fopen("employees.txt", "rb");
if (pf == NULL)
{
perror("fopen error!\n");
return;
}
employee tmp;
while (fread(&tmp, sizeof(employee), 1, pf))
{
SLPushBack(employees, tmp);
}
fclose(pf);
printf("成功导入历史数据\n");
}
int GetMonthDays(int year, int month)
{
int monthDays[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
if (month == 2 && (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)))
{
return monthDays[month] + 1;
}
return monthDays[month];
}
// 获取输入
void employeeInfoGet(SL* employees)
{
int num = 0;
printf("请输入员工个数:");
scanf("%d", &num);
for (int i = 0; i < num; i++)
{
employee tmp;
printf("请输入第%d个员工\n", i + 1);
printf("请输入员工id:");
scanf("%d", &(tmp.id));
printf("请输入姓名:");
scanf("%s", tmp.name);
printf("请输入员工性别:");
scanf("%s", tmp.gender);
printf("请按照年月日的顺序以空格间隔输入员工生日:");
setBirth:
scanf("%d%*c%d%*c%d", &(tmp.birthday.year),
&(tmp.birthday.month),
&(tmp.birthday.day));
if (tmp.birthday.month < 1 || tmp.birthday.month > 12 ||
(tmp.birthday.day < 1 ||
tmp.birthday.day > GetMonthDays(tmp.birthday.year, tmp.birthday.month)))
{
printf("请重新输入生日\n");
goto setBirth;
}
printf("请输入员工学历:");
scanf("%s", tmp.qualification);
printf("请输入员工职业:");
scanf("%s", tmp.job);
printf("请输入员工电话:");
scanf("%s", tmp.teleNum);
printf("请输入员工的住址:");
scanf("%s", tmp.location);
SLPushBack(employees, tmp);
}
}
// 查找方式菜单
void menuForFind()
{
printf("**************\n");
printf("*1. 员工id\n");
printf("*2. 员工姓名\n");
printf("*3. 退出查找\n");
printf("**************\n");
}
// 按照id查找
int findBy_id(SL* employees, int target)
{
for (int i = 0; i < employees->size; i++)
{
if (employees->SeqList[i].id == target)
{
return i;// 返回对应位置下标
}
}
return -1;
}
// 按照名字查找
int findBy_name(SL* employees, char* target)
{
for (int i = 0; i < employees->size; i++)
{
if (strcmp(employees->SeqList[i].name, target) == 0)
{
return i;// 返回对应位置下标
}
}
return -1;
}
// 查找员工——返回下标
int findEmployee(SL* employees)
{
int choice = 0;
int pos = 0;
menuForFind();
printf("请选择查找方式:");
while (scanf("%d", &choice))
{
switch (choice)
{
case 1:
{
int target = 0;
printf("请输入需要查找的员工id:");
scanf("%d", &target);
pos = findBy_id(employees, target);
return pos;
}
break;
case 2:
{
char name[50] = { 0 };
printf("请输入需要查找的员工姓名:");
scanf("%s", name);
pos = findBy_name(employees, name);
return pos;
}
break;
case 3:
return -1;
default:
menuForFind();
printf("请重新按照菜单输入:");
break;
}
menuForFind();
printf("请选择查找方式:");
}
return -1;
}
// 查找并打印员工信息
void findEmployee_print(SL* employees)
{
// 调用findEmployee函数
int pos = findEmployee(employees);
if (pos != -1)
{
printf("\t员工id:%d", employees->SeqList[pos].id);
printf("\t姓名:%s", employees->SeqList[pos].name);
printf("\t性别:%s", employees->SeqList[pos].gender);
printf("\t生日:%d-%02d-%02d\n", employees->SeqList[pos].birthday.year,
employees->SeqList[pos].birthday.month,
employees->SeqList[pos].birthday.day);
printf("\t学历:%s", employees->SeqList[pos].qualification);
printf("\t职业:%s", employees->SeqList[pos].job);
printf("\t电话:%s", employees->SeqList[pos].teleNum);
printf("\t地址:%s\n", employees->SeqList[pos].location);
}
else
{
printf("查无此人\n");
}
}
// 修改菜单
void menuForModify()
{
printf("***修改内容*****\n");
printf("*1. 员工id\n");
printf("*2. 姓名\n");
printf("*3. 性别\n");
printf("*4. 生日\n");
printf("*5. 学历\n");
printf("*6. 职业\n");
printf("*7. 电话\n");
printf("*8. 地址\n");
printf("*9. 退出修改\n");
printf("**************\n");
}
// 生日菜单
//void menuForBirthday()
//{
// printf("**************\n");
// printf("*1. 年\n");
// printf("*2. 月\n");
// printf("*3. 日\n");
// printf("*4. 退出修改\n");
// printf("**************\n");
//}
// 修改员工
void modifyEmployee(SL* employees)
{
// 调用查找函数找出需要修改的员工
int pos = findEmployee(employees);
if (pos == -1)
{
printf("查无此人\n");
pos = findEmployee(employees);
}
int choice = 0;
menuForModify();
printf("请选择需要修改的内容:");
while (scanf(" %d", &choice))
{
switch (choice)
{
case 1:
printf("请输入需要修改的id:");
scanf("%d", &(employees->SeqList[pos].id));
printf("修改完成\n");
break;
case 2:
printf("请输入需要修改的姓名:");
scanf("%s", employees->SeqList[pos].name);
printf("修改完成\n");
break;
case 3:
printf("请输入需要修改的性别:");
scanf("%s", employees->SeqList[pos].gender);
printf("修改完成\n");
break;
case 4:
{
/*int ret = 0;
menuForBirthday();
printf("请选择生日中需要修改的字段:");
while (scanf("%d", &ret))
{
switch (ret)
{
case 1:
printf("请输入需要修改的年:");
setYear:
scanf("%d", &(employees->SeqList[pos].birthday.year));
if (employees->SeqList[pos].birthday.year < 0)
{
printf("年份不合法,请重新输入需要修改的年份:\n");
goto setYear;
}
printf("修改完成\n");
break;
case 2:
printf("请输入需要修改的月:");
setMonth:
scanf("%d", &(employees->SeqList[pos].birthday.month));
if (employees->SeqList[pos].birthday.month < 1 ||
employees->SeqList[pos].birthday.month > 12)
{
printf("月份不合法,请重新输入月份:\n");
goto setMonth;
}
printf("修改完成\n");
break;
case 3:
printf("请输入需要修改的日:");
setDay:
scanf("%d", &(employees->SeqList[pos].birthday.day));
if (employees->SeqList[pos].birthday.month < 1 ||
employees->SeqList[pos].birthday.month > 12 ||
(employees->SeqList[pos].birthday.day < 1 ||
employees->SeqList[pos].birthday.day >
GetMonthDays(employees->SeqList[pos].birthday.year,
employees->SeqList[pos].birthday.month)))
{
printf("日不合法,请重新输入日:\n");
goto setDay;
}
printf("修改完成\n");
break;
case 4:
goto choose;
default:
printf("请重新按照菜单选择\n");
break;
}
menuForBirthday();
printf("请选择生日中需要修改的字段:");
}*/
modifyBirth:
printf("请输入修改后的年月日,以空格间隔:");
scanf("%d%*c%d%*c%d", &(employees->SeqList[pos].birthday.year),
&(employees->SeqList[pos].birthday.month),
&(employees->SeqList[pos].birthday.day));
if (e