员工绩效管理系统c语言代码 需要有创建记录 显示所有记录 清空所有记录 保存记录到文件 从文件读取记录 查询记录 删除记录 添加记录 修改记录 绩效排名的功能
时间: 2023-09-04 22:10:55 浏览: 87
C语言员工管理系统 通过动态链表的创建,插入,删除,更新,查询
以下是一个简单的员工绩效管理系统,包括了创建记录、显示所有记录、清空所有记录、保存记录到文件、从文件读取记录、查询记录、删除记录、添加记录、修改记录和绩效排名的功能。
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_EMPLOYEES 100
typedef struct Employee {
char name[20];
int age;
float performance;
} Employee;
Employee employees[MAX_EMPLOYEES];
int num_employees = 0;
void create_record() {
if (num_employees == MAX_EMPLOYEES) {
printf("Error: too many employees\n");
return;
}
Employee e;
printf("Enter name: ");
scanf("%s", e.name);
printf("Enter age: ");
scanf("%d", &e.age);
printf("Enter performance: ");
scanf("%f", &e.performance);
employees[num_employees] = e;
num_employees++;
}
void display_records() {
printf("Name\tAge\tPerformance\n");
for (int i = 0; i < num_employees; i++) {
printf("%s\t%d\t%.2f\n", employees[i].name, employees[i].age, employees[i].performance);
}
}
void clear_records() {
num_employees = 0;
}
void save_records() {
FILE *f = fopen("employees.txt", "w");
if (f == NULL) {
printf("Error: could not open file for writing\n");
return;
}
for (int i = 0; i < num_employees; i++) {
fprintf(f, "%s %d %.2f\n", employees[i].name, employees[i].age, employees[i].performance);
}
fclose(f);
}
void load_records() {
FILE *f = fopen("employees.txt", "r");
if (f == NULL) {
printf("Error: could not open file for reading\n");
return;
}
Employee e;
while (fscanf(f, "%s %d %f", e.name, &e.age, &e.performance) == 3) {
employees[num_employees] = e;
num_employees++;
}
fclose(f);
}
void search_records() {
char name[20];
printf("Enter name: ");
scanf("%s", name);
for (int i = 0; i < num_employees; i++) {
if (strcmp(employees[i].name, name) == 0) {
printf("Name\tAge\tPerformance\n");
printf("%s\t%d\t%.2f\n", employees[i].name, employees[i].age, employees[i].performance);
return;
}
}
printf("Employee not found\n");
}
void delete_record() {
char name[20];
printf("Enter name: ");
scanf("%s", name);
for (int i = 0; i < num_employees; i++) {
if (strcmp(employees[i].name, name) == 0) {
for (int j = i; j < num_employees - 1; j++) {
employees[j] = employees[j+1];
}
num_employees--;
printf("Employee deleted\n");
return;
}
}
printf("Employee not found\n");
}
void add_record() {
char name[20];
printf("Enter name: ");
scanf("%s", name);
for (int i = 0; i < num_employees; i++) {
if (strcmp(employees[i].name, name) == 0) {
printf("Error: employee already exists\n");
return;
}
}
if (num_employees == MAX_EMPLOYEES) {
printf("Error: too many employees\n");
return;
}
Employee e;
strcpy(e.name, name);
printf("Enter age: ");
scanf("%d", &e.age);
printf("Enter performance: ");
scanf("%f", &e.performance);
employees[num_employees] = e;
num_employees++;
}
void modify_record() {
char name[20];
printf("Enter name: ");
scanf("%s", name);
for (int i = 0; i < num_employees; i++) {
if (strcmp(employees[i].name, name) == 0) {
printf("Enter new age: ");
scanf("%d", &employees[i].age);
printf("Enter new performance: ");
scanf("%f", &employees[i].performance);
printf("Employee modified\n");
return;
}
}
printf("Employee not found\n");
}
void rank_records() {
for (int i = 0; i < num_employees - 1; i++) {
for (int j = i + 1; j < num_employees; j++) {
if (employees[i].performance < employees[j].performance) {
Employee tmp = employees[i];
employees[i] = employees[j];
employees[j] = tmp;
}
}
}
printf("Rank\tName\tPerformance\n");
for (int i = 0; i < num_employees; i++) {
printf("%d\t%s\t%.2f\n", i+1, employees[i].name, employees[i].performance);
}
}
int main() {
int choice;
while (1) {
printf("\nEmployee Performance Management System\n");
printf("---------------------------------------\n");
printf("1. Create record\n");
printf("2. Display all records\n");
printf("3. Clear all records\n");
printf("4. Save records to file\n");
printf("5. Load records from file\n");
printf("6. Search record\n");
printf("7. Delete record\n");
printf("8. Add record\n");
printf("9. Modify record\n");
printf("10. Rank records by performance\n");
printf("11. Exit\n");
printf("---------------------------------------\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1: create_record(); break;
case 2: display_records(); break;
case 3: clear_records(); break;
case 4: save_records(); break;
case 5: load_records(); break;
case 6: search_records(); break;
case 7: delete_record(); break;
case 8: add_record(); break;
case 9: modify_record(); break;
case 10: rank_records(); break;
case 11: exit(0);
default: printf("Invalid choice\n");
}
}
return 0;
}
```
阅读全文