教务管理系统c语言
时间: 2023-07-03 09:06:46 浏览: 126
教务管理系统可以使用C语言进行开发,但需要考虑到各种功能的实现和界面的设计。以下是一个简单的教务管理系统的C语言代码示例,仅供参考。
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENT_NUM 100
struct Student {
int id;
char name[20];
int score;
};
struct Student students[MAX_STUDENT_NUM];
int student_num = 0;
void add_student() {
if (student_num >= MAX_STUDENT_NUM) {
printf("Error: too many students!\n");
return;
}
printf("Enter student id: ");
scanf("%d", &students[student_num].id);
printf("Enter student name: ");
scanf("%s", students[student_num].name);
printf("Enter student score: ");
scanf("%d", &students[student_num].score);
student_num++;
printf("New student added.\n");
}
void print_students() {
printf("ID\tName\tScore\n");
for (int i = 0; i < student_num; i++) {
printf("%d\t%s\t%d\n", students[i].id, students[i].name, students[i].score);
}
}
void search_student() {
int id;
printf("Enter student id to search: ");
scanf("%d", &id);
for (int i = 0; i < student_num; i++) {
if (students[i].id == id) {
printf("ID\tName\tScore\n");
printf("%d\t%s\t%d\n", students[i].id, students[i].name, students[i].score);
return;
}
}
printf("Student not found.\n");
}
void modify_student() {
int id;
printf("Enter student id to modify: ");
scanf("%d", &id);
for (int i = 0; i < student_num; i++) {
if (students[i].id == id) {
printf("Enter new student name: ");
scanf("%s", students[i].name);
printf("Enter new student score: ");
scanf("%d", &students[i].score);
printf("Student modified.\n");
return;
}
}
printf("Student not found.\n");
}
void delete_student() {
int id;
printf("Enter student id to delete: ");
scanf("%d", &id);
for (int i = 0; i < student_num; i++) {
if (students[i].id == id) {
for (int j = i; j < student_num - 1; j++) {
students[j] = students[j + 1];
}
student_num--;
printf("Student deleted.\n");
return;
}
}
printf("Student not found.\n");
}
int main() {
int choice;
while (1) {
printf("Menu:\n");
printf("1. Add student\n");
printf("2. Print all students\n");
printf("3. Search student\n");
printf("4. Modify student\n");
printf("5. Delete student\n");
printf("6. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
print_students();
break;
case 3:
search_student();
break;
case 4:
modify_student();
break;
case 5:
delete_student();
break;
case 6:
return 0;
default:
printf("Invalid choice.\n");
}
}
return 0;
}
```
这个示例实现了添加、查询、修改和删除学生信息的功能,通过一个菜单来选择操作。当然,这个示例还可以进行更多的优化和改进。
阅读全文