c语言实现学生管理系统
时间: 2023-07-13 10:13:44 浏览: 50
好的,学生管理系统的基本功能包括添加学生信息、修改学生信息、删除学生信息、查询学生信息等操作。以下是一个简单的 C 语言实现学生管理系统的例子:
```c
#include <stdio.h>
#include <string.h>
#define MAX_STUDENT_NUM 100 // 学生信息最大数量
// 学生信息结构体
struct student {
char id[10]; // 学号
char name[20]; // 姓名
char gender[5]; // 性别
int age; // 年龄
};
struct student students[MAX_STUDENT_NUM]; // 存储学生信息的数组
int student_num = 0; // 学生数量
// 添加学生信息
void add_student() {
if (student_num >= MAX_STUDENT_NUM) {
printf("已达到学生信息最大数量,无法添加!\n");
return;
}
struct student new_student;
printf("请输入学生学号:");
scanf("%s", new_student.id);
printf("请输入学生姓名:");
scanf("%s", new_student.name);
printf("请输入学生性别:");
scanf("%s", new_student.gender);
printf("请输入学生年龄:");
scanf("%d", &new_student.age);
students[student_num] = new_student;
student_num++;
printf("添加学生信息成功!\n");
}
// 修改学生信息
void modify_student() {
char id[10];
printf("请输入要修改的学生学号:");
scanf("%s", id);
int index = -1;
for (int i = 0; i < student_num; i++) {
if (strcmp(students[i].id, id) == 0) {
index = i;
break;
}
}
if (index == -1) {
printf("未找到该学生信息!\n");
return;
}
printf("请输入学生姓名:");
scanf("%s", students[index].name);
printf("请输入学生性别:");
scanf("%s", students[index].gender);
printf("请输入学生年龄:");
scanf("%d", &students[index].age);
printf("修改学生信息成功!\n");
}
// 删除学生信息
void delete_student() {
char id[10];
printf("请输入要删除的学生学号:");
scanf("%s", id);
int index = -1;
for (int i = 0; i < student_num; i++) {
if (strcmp(students[i].id, id) == 0) {
index = i;
break;
}
}
if (index == -1) {
printf("未找到该学生信息!\n");
return;
}
for (int i = index; i < student_num - 1; i++) {
students[i] = students[i + 1];
}
student_num--;
printf("删除学生信息成功!\n");
}
// 查询学生信息
void query_student() {
char id[10];
printf("请输入要查询的学生学号:");
scanf("%s", id);
int index = -1;
for (int i = 0; i < student_num; i++) {
if (strcmp(students[i].id, id) == 0) {
index = i;
break;
}
}
if (index == -1) {
printf("未找到该学生信息!\n");
return;
}
printf("学号:%s\n", students[index].id);
printf("姓名:%s\n", students[index].name);
printf("性别:%s\n", students[index].gender);
printf("年龄:%d\n", students[index].age);
}
// 主函数
int main() {
int choice;
while (1) {
printf("\n");
printf("1. 添加学生信息\n");
printf("2. 修改学生信息\n");
printf("3. 删除学生信息\n");
printf("4. 查询学生信息\n");
printf("0. 退出系统\n");
printf("请选择操作:");
scanf("%d", &choice);
switch (choice) {
case 0:
printf("感谢使用学生管理系统,再见!\n");
return 0;
case 1:
add_student();
break;
case 2:
modify_student();
break;
case 3:
delete_student();
break;
case 4:
query_student();
break;
default:
printf("输入的操作不正确,请重新选择!\n");
}
}
}
```
以上代码只是一个简单的例子,实际使用时需要根据具体需求进行修改和完善。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)