本项目是一个简单的薪资管理系统,旨在为用户提供方便的员工薪资管理功能,如添加、查询、修改、删除员工薪资信息等。系统通过命令行交互界面与用户进行交互,并使用 txt 文件存储员工数据。
操作系统:windows, linux
开发环境工具:qt, vscode, visual studio
技术要求:
添加员工信息:允许用户添加新的员工及其薪资信息。
查询员工薪资:根据员工 ID 查询其薪资信息。
修改员工薪资:根据员工 ID 修改其薪资信息。
删除员工信息:根据员工 ID 删除其薪资信息。
显示所有员工信息:显示当前所有员工的薪资信息。
void addemployee() {
if (current_employee_count >= MAX_EMPLOYEES) {
printf("员工数量已达上限!\n");
return;
}
Employee new_employee;
printf("请输入员工工号:");
scanf("%d", &new_employee.id);
printf("请输入员工姓名:");
scanf("%s", new_employee.name);
printf("请输入员工基本工资:");
scanf("%f", &new_employee.base_salary);
printf("请输入员工奖金:");
scanf("%f", &new_employee.bonus);
new_employee.total_salary = new_employee.base_salary + new_employee.bonus;
employees[current_employee_count] = new_employee;
current_employee_count++;
printf("员工信息已成功录入!\n");
savetofile(); // 保存数据到文件
}
void searchsalary() {
int search_id;
char search_name[50];
int search_option;
printf("1. 通过工号查询\n2. 通过姓名查询\n请选择查询方式:");
scanf("%d", &search_option);
int found = 0;
if (search_option == 1) {
printf("请输入员工工号:");
scanf("%d", &search_id);
for (int i = 0; i < current_employee_count; i++) {
if (employees[i].id == search_id) {
printf("姓名:%s, 基本工资:%f, 奖金:%f, 总薪资:%f\n",
employees[i].name, employees[i].base_salary, employees[i].bonus, employees[i].total_salary);
found = 1;
break;
}
}
} else if (search_option == 2) {
printf("请输入员工姓名:");
scanf("%s", search_name);
for (int i = 0; i < current_employee_count; i++) {
if (strcmp(employees[i].name, search_name) == 0) {
printf("工号:%d, 基本工资:%f, 奖金:%f, 总薪资:%f\n",
employees[i].id, employees[i].base_salary, employees[i].bonus, employees[i].total_salary);
found = 1;
break;
}
}
}
if (!found) {
printf("未找到相关员工信息。\n");
}
}
void modifysalary() {
int modify_id;
printf("请输入需要修改的员工工号:");
scanf("%d", &modify_id);
int found = 0;
for (int i = 0; i < current_employee_count; i++) {
if (employees[i].id == modify_id) {
printf("当前工资:%f, 当前奖金:%f\n", employees[i].base_salary, employees[i].bonus);
printf("请输入新的基本工资:");
scanf("%f", &employees[i].base_salary);
printf("请输入新的奖金:");
scanf("%f", &employees[i].bonus);
employees[i].total_salary = employees[i].base_salary + employees[i].bonus;
printf("修改成功!\n");
savetofile(); // 保存数据到文件
found = 1;
break;
}
}
if (!found) {
printf("未找到该工号的员工。\n");
}
}
void deleteemployee() {
int delete_id;
printf("请输入需要删除的员工工号:");
scanf("%d", &delete_id);
int found = 0;
for (int i = 0; i < current_employee_count; i++) {
if (employees[i].id == delete_id) {
for (int j = i; j < current_employee_count - 1; j++) {
employees[j] = employees[j+1];
}
current_employee_count--;
printf("删除成功!\n");
savetofile(); // 保存数据到文件
found = 1;
break;
}
}
if (!found) {
printf("未找到该工号的员工。\n");
}
}
void displayall() {
printf("工号\t姓名\t基本工资\t奖金\t总薪资\n");
printf("---------------------------------------------------\n");
for (int i = 0; i < current_employee_count; i++) {
printf("%d\t%s\t%f\t%f\t%f\n",
employees[i].id, employees[i].name, employees[i].base_salary, employees[i].bonus, employees[i].total_salary);
}
}
代码已开源,可访问gitee下载。
本项目为初学者提供了一个实际的 C 语言编程实践,涉及文件操作、数据结构设计和命令行交互界面的基本应用。希望此项目能对学习者有所帮助,并鼓励在此基础上进行更多的拓展和改进。