3.教师工作最管理系统 建立教师工作量管系统,对教师工作量相关信息进行管理。教师工作量相关信息包括教师工号、教师姓名、学期、工作量和年度总工作量等。具体要求如下: (1)建立该系统的存储结构。 (2)录入教师每个学斯的工作量信息。 (3)查找菜个教师某个学期的工作量。 (4)修改某个教师某个学期的工作量 (5)删除某个教师工作量的相关信息 (6)统计某个教师年度总工作量。 (7)对教师的年度总工作量进行排名。 用c语言编写该题目
时间: 2024-03-16 14:43:44 浏览: 59
以下是一个简单的教师工作量管理系统的代码,包括存储结构、录入、查找、修改、删除、统计和排名功能。请注意,这只是一个简单的示例代码,可以根据需要进行修改和完善。
```
#include <stdio.h>
#include <string.h>
#define MAX_TEACHERS 100
typedef struct {
int id; // 教师工号
char name[20]; // 教师姓名
int term; // 学期
int workload; // 工作量
} Teacher;
typedef struct {
Teacher teachers[MAX_TEACHERS]; // 教师数组
int count; // 教师数量
} TeacherList;
// 初始化教师列表
void initTeachers(TeacherList *list) {
list->count = 0;
}
// 添加教师信息
void addTeacher(TeacherList *list, int id, char *name, int term, int workload) {
if (list->count >= MAX_TEACHERS) {
printf("Teacher list is full.\n");
return;
}
Teacher *teacher = &list->teachers[list->count];
teacher->id = id;
strcpy(teacher->name, name);
teacher->term = term;
teacher->workload = workload;
list->count++;
}
// 查找教师信息
Teacher *findTeacher(TeacherList *list, int id, int term) {
for (int i = 0; i < list->count; i++) {
Teacher *teacher = &list->teachers[i];
if (teacher->id == id && teacher->term == term) {
return teacher;
}
}
return NULL;
}
// 修改教师信息
void updateTeacher(TeacherList *list, int id, int term, int workload) {
Teacher *teacher = findTeacher(list, id, term);
if (teacher == NULL) {
printf("Teacher not found.\n");
return;
}
teacher->workload = workload;
}
// 删除教师信息
void deleteTeacher(TeacherList *list, int id, int term) {
for (int i = 0; i < list->count; i++) {
Teacher *teacher = &list->teachers[i];
if (teacher->id == id && teacher->term == term) {
for (int j = i; j < list->count - 1; j++) {
list->teachers[j] = list->teachers[j + 1];
}
list->count--;
printf("Teacher deleted.\n");
return;
}
}
printf("Teacher not found.\n");
}
// 统计教师年度总工作量
int calcYearWorkload(TeacherList *list, int id) {
int yearWorkload = 0;
for (int i = 0; i < list->count; i++) {
Teacher *teacher = &list->teachers[i];
if (teacher->id == id) {
yearWorkload += teacher->workload;
}
}
return yearWorkload;
}
// 排序教师年度总工作量
void sortTeachers(TeacherList *list) {
for (int i = 0; i < list->count - 1; i++) {
for (int j = 0; j < list->count - i - 1; j++) {
int workload1 = calcYearWorkload(list, list->teachers[j].id);
int workload2 = calcYearWorkload(list, list->teachers[j + 1].id);
if (workload1 < workload2) {
Teacher temp = list->teachers[j];
list->teachers[j] = list->teachers[j + 1];
list->teachers[j + 1] = temp;
}
}
}
}
int main() {
TeacherList list;
initTeachers(&list);
// 添加教师信息
addTeacher(&list, 1001, "张三", 1, 200);
addTeacher(&list, 1002, "李四", 1, 180);
addTeacher(&list, 1003, "王五", 1, 220);
addTeacher(&list, 1001, "张三", 2, 180);
addTeacher(&list, 1002, "李四", 2, 200);
addTeacher(&list, 1003, "王五", 2, 190);
// 查找教师信息
Teacher *teacher = findTeacher(&list, 1001, 1);
if (teacher != NULL) {
printf("%d %s %d %d\n", teacher->id, teacher->name, teacher->term, teacher->workload);
} else {
printf("Teacher not found.\n");
}
// 修改教师信息
updateTeacher(&list, 1001, 1, 220);
// 删除教师信息
deleteTeacher(&list, 1002, 1);
// 统计教师年度总工作量
int yearWorkload = calcYearWorkload(&list, 1001);
printf("Year workload of teacher 1001: %d\n", yearWorkload);
// 排序教师年度总工作量
sortTeachers(&list);
for (int i = 0; i < list.count; i++) {
Teacher *teacher = &list.teachers[i];
printf("%d %s %d %d\n", teacher->id, teacher->name, teacher->term, teacher->workload);
}
return 0;
}
```
阅读全文