用c语言写一个学籍管理系统
时间: 2023-12-24 12:03:21 浏览: 68
学籍管理系统主要包括以下功能:
1. 学生信息录入
2. 学生信息查询
3. 学生信息修改
4. 学生信息删除
下面是一个简单的学籍管理系统的代码,使用 C 语言实现:
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENT_NUM 100
typedef struct {
char name[20];
int age;
char gender[6];
char id[20];
char department[20];
} Student;
Student students[MAX_STUDENT_NUM];
int student_num = 0;
void add_student() {
if (student_num >= MAX_STUDENT_NUM) {
printf("Student database is full.\n");
return;
}
printf("Please input student's name, age, gender, id and department:\n");
scanf("%s%d%s%s%s", students[student_num].name, &students[student_num].age,
students[student_num].gender, students[student_num].id, students[student_num].department);
student_num++;
printf("Add student successfully.\n");
}
void search_student() {
char id[20];
printf("Please input student's id:\n");
scanf("%s", id);
for (int i = 0; i < student_num; i++) {
if (strcmp(students[i].id, id) == 0) {
printf("Name: %s, Age: %d, Gender: %s, Id: %s, Department: %s\n",
students[i].name, students[i].age, students[i].gender, students[i].id, students[i].department);
return;
}
}
printf("Can not find this student.\n");
}
void update_student() {
char id[20];
printf("Please input student's id:\n");
scanf("%s", id);
for (int i = 0; i < student_num; i++) {
if (strcmp(students[i].id, id) == 0) {
printf("Please input student's name, age, gender and department:\n");
scanf("%s%d%s%s", students[i].name, &students[i].age,
students[i].gender, students[i].department);
printf("Update student information successfully.\n");
return;
}
}
printf("Can not find this student.\n");
}
void delete_student() {
char id[20];
printf("Please input student's id:\n");
scanf("%s", id);
for (int i = 0; i < student_num; i++) {
if (strcmp(students[i].id, id) == 0) {
for (int j = i; j < student_num - 1; j++) {
students[j] = students[j + 1];
}
student_num--;
printf("Delete student successfully.\n");
return;
}
}
printf("Can not find this student.\n");
}
void print_menu() {
printf("\n");
printf("********** Student Management System ***********\n");
printf("* 1. Add student *\n");
printf("* 2. Search student *\n");
printf("* 3. Update student *\n");
printf("* 4. Delete student *\n");
printf("* 5. Exit *\n");
printf("************************************************\n");
printf("\n");
}
int main() {
int choice;
while (1) {
print_menu();
printf("Please input your choice:\n");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
search_student();
break;
case 3:
update_student();
break;
case 4:
delete_student();
break;
case 5:
printf("Exit.\n");
return 0;
default:
printf("Invalid choice, please input again.\n");
break;
}
}
return 0;
}
```
上面的代码实现了一个简单的学籍管理系统,包括了添加学生、查询学生、修改学生和删除学生等功能。用户可以根据菜单提示进行操作。
阅读全文