写一个关于教师工资管理系统的c语言程序
时间: 2024-03-13 17:47:30 浏览: 49
c语言教师工资管理系统
5星 · 资源好评率100%
这是一个简单的教师工资管理系统的C语言程序:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100
// 定义教师结构体
typedef struct {
char name[20];
int age;
int salary;
} Teacher;
// 添加教师信息
void addTeacher(Teacher *teachers, int *count) {
printf("请输入教师姓名:");
scanf("%s", teachers[*count].name);
printf("请输入教师年龄:");
scanf("%d", &teachers[*count].age);
printf("请输入教师工资:");
scanf("%d", &teachers[*count].salary);
(*count)++;
printf("添加成功!\n");
}
// 删除教师信息
void deleteTeacher(Teacher *teachers, int *count) {
char name[20];
printf("请输入要删除的教师姓名:");
scanf("%s", name);
int i, j;
for (i = 0; i < *count; i++) {
if (strcmp(teachers[i].name, name) == 0) {
for (j = i; j < *count - 1; j++) {
teachers[j] = teachers[j + 1];
}
(*count)--;
printf("删除成功!\n");
return;
}
}
printf("未找到该教师信息!\n");
}
// 修改教师信息
void modifyTeacher(Teacher *teachers, int count) {
char name[20];
printf("请输入要修改的教师姓名:");
scanf("%s", name);
int i;
for (i = 0; i < count; i++) {
if (strcmp(teachers[i].name, name) == 0) {
printf("请输入教师年龄:");
scanf("%d", &teachers[i].age);
printf("请输入教师工资:");
scanf("%d", &teachers[i].salary);
printf("修改成功!\n");
return;
}
}
printf("未找到该教师信息!\n");
}
// 查询教师信息
void queryTeacher(Teacher *teachers, int count) {
char name[20];
printf("请输入要查询的教师姓名:");
scanf("%s", name);
int i;
for (i = 0; i < count; i++) {
if (strcmp(teachers[i].name, name) == 0) {
printf("姓名:%s,年龄:%d,工资:%d\n", teachers[i].name, teachers[i].age, teachers[i].salary);
return;
}
}
printf("未找到该教师信息!\n");
}
// 显示所有教师信息
void displayTeachers(Teacher *teachers, int count) {
int i;
for (i = 0; i < count; i++) {
printf("姓名:%s,年龄:%d,工资:%d\n", teachers[i].name, teachers[i].age, teachers[i].salary);
}
}
int main() {
Teacher teachers[MAX];
int count = 0;
int choice;
while (1) {
printf("教师工资管理系统\n");
printf("1. 添加教师信息\n");
printf("2. 删除教师信息\n");
printf("3. 修改教师信息\n");
printf("4. 查询教师信息\n");
printf("5. 显示所有教师信息\n");
printf("6. 退出程序\n");
printf("请选择操作:");
scanf("%d", &choice);
switch (choice) {
case 1:
addTeacher(teachers, &count);
break;
case 2:
deleteTeacher(teachers, &count);
break;
case 3:
modifyTeacher(teachers, count);
break;
case 4:
queryTeacher(teachers, count);
break;
case 5:
displayTeachers(teachers, count);
break;
case 6:
printf("程序已退出!\n");
exit(0);
default:
printf("无效操作!\n");
}
}
return 0;
}
```
这个程序可以实现基本的添加、删除、修改、查询和显示所有教师信息的功能。你可以根据需要添加其他功能,比如文件读写、排序等等。
阅读全文