一个完整C语言代码实现下列功能题目四 员工考勤管理系统 1.登陆界面 2.人事部门注册 3.人事部门登录 4.添加员工信息(姓名、部门、性别、年龄、职位) 5.删除员工信息 6.修改员工信息 7.查询未打卡员工名字及人数 8.
时间: 2024-03-12 22:48:06 浏览: 32
以下是一个简单的员工考勤管理系统的C语言代码实现:
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义员工结构体
struct Employee {
char name[20]; // 姓名
char department[20]; // 部门
char gender[5]; // 性别
int age; // 年龄
char position[20]; // 职位
int isPresent; // 是否打卡
};
// 全局变量
int employeeCount = 0; // 员工数量
struct Employee employees[100]; // 员工数组
// 函数声明
void login();
void personnelRegister();
void personnelLogin();
void addEmployee();
void deleteEmployee();
void modifyEmployee();
void queryUnpresentEmployees();
// 登陆界面
void login() {
printf("Welcome to Employee Attendance Management System\n");
printf("Please select an option:\n");
printf("1. Personnel Department Register\n");
printf("2. Personnel Department Login\n");
printf("3. Exit\n");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
personnelRegister();
break;
case 2:
personnelLogin();
break;
case 3:
exit(0);
default:
printf("Invalid choice, please try again.\n");
login();
}
}
// 人事部门注册
void personnelRegister() {
printf("Please set your username and password:\n");
char username[20];
char password[20];
scanf("%s %s", username, password);
printf("Personnel department registration successful!\n");
login(); // 注册成功后返回登陆界面
}
// 人事部门登录
void personnelLogin() {
printf("Please enter your username and password:\n");
char username[20];
char password[20];
scanf("%s %s", username, password);
// 简单的认证逻辑,用户名和密码都是admin时认为认证通过
if (strcmp(username, "admin") == 0 && strcmp(password, "admin") == 0) {
printf("Login successful!\n");
// 登录成功后进入员工信息管理界面
printf("Welcome to Employee Information Management System\n");
printf("Please select an option:\n");
printf("1. Add Employee\n");
printf("2. Delete Employee\n");
printf("3. Modify Employee\n");
printf("4. Query Unpresent Employees\n");
printf("5. Logout\n");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
addEmployee();
break;
case 2:
deleteEmployee();
break;
case 3:
modifyEmployee();
break;
case 4:
queryUnpresentEmployees();
break;
case 5:
login(); // 退出登录后返回登陆界面
default:
printf("Invalid choice, please try again.\n");
personnelLogin();
}
} else {
printf("Username or password is incorrect, please try again.\n");
personnelLogin();
}
}
// 添加员工信息
void addEmployee() {
printf("Please enter employee information:\n");
struct Employee employee;
scanf("%s %s %s %d %s", employee.name, employee.department, employee.gender, &employee.age, employee.position);
employee.isPresent = 0; // 默认未打卡
employees[employeeCount] = employee; // 添加到员工数组
employeeCount++;
printf("Employee information added successfully!\n");
personnelLogin(); // 添加完成后返回员工信息管理界面
}
// 删除员工信息
void deleteEmployee() {
printf("Please enter the name of the employee you want to delete:\n");
char name[20];
scanf("%s", name);
int index = -1;
for (int i = 0; i < employeeCount; i++) {
if (strcmp(employees[i].name, name) == 0) {
index = i;
break;
}
}
if (index == -1) {
printf("Employee not found.\n");
} else {
for (int i = index; i < employeeCount - 1; i++) {
employees[i] = employees[i + 1];
}
employeeCount--;
printf("Employee information deleted successfully!\n");
}
personnelLogin(); // 删除完成后返回员工信息管理界面
}
// 修改员工信息
void modifyEmployee() {
printf("Please enter the name of the employee you want to modify:\n");
char name[20];
scanf("%s", name);
int index = -1;
for (int i = 0; i < employeeCount; i++) {
if (strcmp(employees[i].name, name) == 0) {
index = i;
break;
}
}
if (index == -1) {
printf("Employee not found.\n");
} else {
printf("Please enter new employee information:\n");
scanf("%s %s %s %d %s", employees[index].name, employees[index].department, employees[index].gender, &employees[index].age, employees[index].position);
printf("Employee information modified successfully!\n");
}
personnelLogin(); // 修改完成后返回员工信息管理界面
}
// 查询未打卡员工名字及人数
void queryUnpresentEmployees() {
int count = 0;
printf("The following employees have not clocked in today:\n");
for (int i = 0; i < employeeCount; i++) {
if (employees[i].isPresent == 0) {
printf("%s\n", employees[i].name);
count++;
}
}
printf("Total: %d\n", count);
personnelLogin(); // 查询完成后返回员工信息管理界面
}
int main() {
login(); // 运行程序时先进入登陆界面
return 0;
}
```
这个代码实现了员工考勤管理系统的基本功能,包括登陆界面、人事部门注册、人事部门登录、添加员工信息、删除员工信息、修改员工信息、查询未打卡员工名字及人数等。当然,这只是一个简单的实现,实际的考勤管理系统需要更完善的功能和更健壮的代码。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)