c语言编程职工工资信息管理系统
时间: 2023-12-28 21:25:58 浏览: 42
以下是一个简单的C语言编程职工工资信息管理系统的设计:
```c
#include <stdio.h>
#include <string.h>
struct Employee {
char no[10];
char name[20];
char gender[10];
int age;
int salary;
};
void addEmployee(struct Employee emp[], int *count) {
printf("请输入职工号:");
scanf("%s", emp[*count].no);
printf("请输入姓名:");
scanf("%s", emp[*count].name);
printf("请输入性别:");
scanf("%s", emp[*count].gender);
printf("请输入年龄:");
scanf("%d", &emp[*count].age);
printf("请输入工资:");
scanf("%d", &emp[*count].salary);
(*count)++;
printf("职工信息添加成功!\n");
}
void searchEmployee(struct Employee emp[], int count) {
char searchNo[10];
printf("请输入要查询的职工号:");
scanf("%s", searchNo);
for (int i = 0; i < count; i++) {
if (strcmp(emp[i].no, searchNo) == 0) {
printf("职工号:%s\n", emp[i].no);
printf("姓名:%s\n", emp[i].name);
printf("性别:%s\n", emp[i].gender);
printf("年龄:%d\n", emp[i].age);
printf("工资:%d\n", emp[i].salary);
return;
}
}
printf("未找到该职工号对应的职工信息!\n");
}
void deleteEmployee(struct Employee emp[], int *count) {
char deleteNo[10];
printf("请输入要删除的职工号:");
scanf("%s", deleteNo);
for (int i = 0; i < *count; i++) {
if (strcmp(emp[i].no, deleteNo) == 0) {
for (int j = i; j < *count - 1; j++) {
emp[j] = emp[j + 1];
}
(*count)--;
printf("职工信息删除成功!\n");
return;
}
}
printf("未找到该职工号对应的职工信息!\n");
}
void sortEmployee(struct Employee emp[], int count) {
struct Employee temp;
for (int i = 0; i < count - 1; i++) {
for (int j = 0; j < count - i - 1; j++) {
if (emp[j].salary > emp[j + 1].salary) {
temp = emp[j];
emp[j] = emp[j + 1];
emp[j + 1] = temp;
}
}
}
printf("职工信息按工资排序成功!\n");
}
int main() {
struct Employee employees[100];
int employeeCount = 0;
int choice;
while (1) {
printf("职工工资信息管理系统\n");
printf("1. 添加职工信息\n");
printf("2. 查询职工信息\n");
printf("3. 删除职工信息\n");
printf("4. 按工资排序职工信息\n");
printf("5. 退出\n");
printf("请输入您的选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
addEmployee(employees, &employeeCount);
break;
case 2:
searchEmployee(employees, employeeCount);
break;
case 3:
deleteEmployee(employees, &employeeCount);
break;
case 4:
sortEmployee(employees, employeeCount);
break;
case 5:
printf("感谢使用职工工资信息管理系统!\n");
return 0;
default:
printf("无效的选择,请重新输入!\n");
break;
}
}
return 0;
}
```