c语言写一个学生学籍管理系统
时间: 2023-09-10 07:13:17 浏览: 89
c语言学生学籍管理系统
好的,下面是一个简单的学生学籍管理系统的C语言代码:
```c
#include <stdio.h>
#include <string.h>
#define MAX_STUDENTS 100
struct Student {
char name[50];
int id;
float gpa;
};
struct Student students[MAX_STUDENTS];
int num_students = 0;
void add_student() {
struct Student s;
printf("Enter name: ");
scanf("%s", s.name);
printf("Enter ID: ");
scanf("%d", &s.id);
printf("Enter GPA: ");
scanf("%f", &s.gpa);
students[num_students++] = s;
}
void print_student(struct Student s) {
printf("Name: %s\n", s.name);
printf("ID: %d\n", s.id);
printf("GPA: %.2f\n", s.gpa);
}
void print_all_students() {
for (int i = 0; i < num_students; i++) {
printf("Student %d:\n", i+1);
print_student(students[i]);
printf("\n");
}
}
void find_student() {
int id;
printf("Enter student ID: ");
scanf("%d", &id);
for (int i = 0; i < num_students; i++) {
if (students[i].id == id) {
printf("Found student:\n");
print_student(students[i]);
return;
}
}
printf("Student not found.\n");
}
int main() {
while (1) {
printf("1. Add student\n");
printf("2. Print all students\n");
printf("3. Find student\n");
printf("4. Quit\n");
int choice;
printf("Enter choice: ");
scanf("%d", &choice);
if (choice == 1) {
add_student();
} else if (choice == 2) {
print_all_students();
} else if (choice == 3) {
find_student();
} else if (choice == 4) {
break;
} else {
printf("Invalid choice.\n");
}
}
return 0;
}
```
这个程序可以添加学生信息、打印所有学生信息、查找特定学生信息。你可以根据需要进行修改和完善,添加其他功能。
阅读全文