教务管理系统c语言
时间: 2023-07-03 08:07:47 浏览: 60
教务管理系统是一个较为复杂的系统,需要涉及到多个模块的设计和开发。在C语言中,可以通过结构体和数组等数据结构来实现。
以下是一个简单的教务管理系统的代码示例:
```c
#include <stdio.h>
#include <string.h>
#define MAX_STUDENT 100 // 最多学生数
#define MAX_SUBJECT 10 // 最多科目数
// 学生结构体
struct Student {
int id; // 学号
char name[20]; // 姓名
int scores[MAX_SUBJECT]; // 分数数组
};
int main() {
struct Student students[MAX_STUDENT]; // 学生数组
int num_students = 0; // 学生数量
int num_subjects = 0; // 科目数量
char subjects[MAX_SUBJECT][20]; // 科目数组
printf("请输入科目数量:");
scanf("%d", &num_subjects);
printf("请依次输入科目名称:\n");
for (int i = 0; i < num_subjects; i++) {
scanf("%s", subjects[i]);
}
// 主菜单
while (1) {
printf("\n欢迎使用教务管理系统\n");
printf("1. 添加学生信息\n");
printf("2. 修改学生信息\n");
printf("3. 删除学生信息\n");
printf("4. 查询学生信息\n");
printf("5. 退出系统\n");
printf("请选择操作:");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
// 添加学生信息
if (num_students >= MAX_STUDENT) {
printf("学生数量已达上限,请删除部分学生信息后再添加\n");
break;
}
printf("请输入学生学号:");
int id;
scanf("%d", &id);
// 检查学生是否已经存在
for (int i = 0; i < num_students; i++) {
if (students[i].id == id) {
printf("学生已存在,无法添加\n");
goto end;
}
}
students[num_students].id = id;
printf("请输入学生姓名:");
scanf("%s", students[num_students].name);
printf("请依次输入各科目的成绩:\n");
for (int i = 0; i < num_subjects; i++) {
printf("%s:", subjects[i]);
scanf("%d", &students[num_students].scores[i]);
}
num_students++;
printf("添加成功\n");
break;
case 2:
// 修改学生信息
printf("请输入要修改的学生学号:");
scanf("%d", &id);
int index = -1; // 学生在数组中的下标
for (int i = 0; i < num_students; i++) {
if (students[i].id == id) {
index = i;
break;
}
}
if (index == -1) {
printf("学生不存在\n");
break;
}
printf("请输入学生姓名(回车不修改):");
char name[20];
scanf("%s", name);
if (strcmp(name, "") != 0) {
strcpy(students[index].name, name);
}
printf("请依次输入各科目的成绩(回车不修改):\n");
for (int i = 0; i < num_subjects; i++) {
printf("%s:", subjects[i]);
int score;
scanf("%d", &score);
if (score != -1) {
students[index].scores[i] = score;
}
}
printf("修改成功\n");
break;
case 3:
// 删除学生信息
printf("请输入要删除的学生学号:");
scanf("%d", &id);
index = -1;
for (int i = 0; i < num_students; i++) {
if (students[i].id == id) {
index = i;
break;
}
}
if (index == -1) {
printf("学生不存在\n");
break;
}
for (int i = index; i < num_students - 1; i++) {
students[i] = students[i + 1];
}
num_students--;
printf("删除成功\n");
break;
case 4:
// 查询学生信息
printf("请输入要查询的学生学号:");
scanf("%d", &id);
index = -1;
for (int i = 0; i < num_students; i++) {
if (students[i].id == id) {
index = i;
break;
}
}
if (index == -1) {
printf("学生不存在\n");
break;
}
printf("学号\t姓名");
for (int i = 0; i < num_subjects; i++) {
printf("\t%s", subjects[i]);
}
printf("\n");
printf("%d\t%s", students[index].id, students[index].name);
for (int i = 0; i < num_subjects; i++) {
printf("\t%d", students[index].scores[i]);
}
printf("\n");
break;
case 5:
// 退出系统
return 0;
default:
printf("无效操作\n");
}
end:;
}
return 0;
}
```
上述代码实现了一个基本的教务管理系统,支持添加、修改、删除、查询学生信息等操作。在代码中,使用了结构体来定义学生信息,使用数组和字符串来存储科目信息。通过使用菜单和循环语句,实现了系统的基本功能。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)