学社学生管理系统 C语言
时间: 2023-12-19 22:05:45 浏览: 28
学生管理系统是一种常见的管理系统,可以用C语言来实现。下面是一个简单的学生管理系统的示例代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENT_NUM 100
struct student {
char name[20];
int age;
int score;
};
struct student students[MAX_STUDENT_NUM];
int student_num = 0;
void add_student() {
if (student_num >= MAX_STUDENT_NUM) {
printf("The number of students has reached the upper limit.\n");
return;
}
struct student s;
printf("Please enter the name of the student:\n");
scanf("%s", s.name);
printf("Please enter the age of the student:\n");
scanf("%d", &s.age);
printf("Please enter the score of the student:\n");
scanf("%d", &s.score);
students[student_num++] = s;
printf("Add student successfully.\n");
}
void delete_student() {
if (student_num <= 0) {
printf("There is no student to delete.\n");
return;
}
char name[20];
printf("Please enter the name of the student you want to delete:\n");
scanf("%s", name);
int i;
for (i = 0; i < student_num; i++) {
if (strcmp(students[i].name, name) == 0) {
break;
}
}
if (i == student_num) {
printf("The student does not exist.\n");
return;
}
for (; i < student_num - 1; i++) {
students[i] = students[i + 1];
}
student_num--;
printf("Delete student successfully.\n");
}
void modify_student() {
if (student_num <= 0) {
printf("There is no student to modify.\n");
return;
}
char name[20];
printf("Please enter the name of the student you want to modify:\n");
scanf("%s", name);
int i;
for (i = 0; i < student_num; i++) {
if (strcmp(students[i].name, name) == 0) {
break;
}
}
if (i == student_num) {
printf("The student does not exist.\n");
return;
}
printf("Please enter the new age of the student:\n");
scanf("%d", &students[i].age);
printf("Please enter the new score of the student:\n");
scanf("%d", &students[i].score);
printf("Modify student successfully.\n");
}
void query_student() {
if (student_num <= 0) {
printf("There is no student to query.\n");
return;
}
char name[20];
printf("Please enter the name of the student you want to query:\n");
scanf("%s", name);
int i;
for (i = 0; i < student_num; i++) {
if (strcmp(students[i].name, name) == 0) {
printf("Name: %s, Age: %d, Score: %d\n", students[i].name, students[i].age, students[i].score);
break;
}
}
if (i == student_num) {
printf("