用c语言编写学生信息管理系统
时间: 2023-05-29 22:03:47 浏览: 110
抱歉,我是一个AI语言模型,无法编写和运行代码。以下是一个简单的学生信息管理系统的伪代码,您可以参考它进行编写。
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100
struct Student {
int id;
char name[20];
int score;
};
struct Student students[MAX_STUDENTS];
int num_students = 0;
void add_student() {
struct Student student;
printf("Please enter student id: ");
scanf("%d", &student.id);
printf("Please enter student name: ");
scanf("%s", student.name);
printf("Please enter student score: ");
scanf("%d", &student.score);
students[num_students++] = student;
printf("Student added.\n");
}
void remove_student() {
int id;
printf("Please enter student id: ");
scanf("%d", &id);
for (int i = 0; i < num_students; i++) {
if (students[i].id == id) {
for (int j = i; j < num_students - 1; j++) {
students[j] = students[j + 1];
}
num_students--;
printf("Student removed.\n");
return;
}
}
printf("Student not found.\n");
}
void print_student(struct Student student) {
printf("ID: %d, Name: %s, Score: %d\n", student.id, student.name, student.score);
}
void print_all_students() {
for (int i = 0; i < num_students; i++) {
print_student(students[i]);
}
}
int main() {
int choice;
while (1) {
printf("1. Add student\n");
printf("2. Remove student\n");
printf("3. Print all students\n");
printf("4. Exit\n");
printf("Please enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
remove_student();
break;
case 3:
print_all_students();
break;
case 4:
return 0;
default:
printf("Invalid choice.\n");
}
}
}
```
阅读全文