为我实现一个完整的C语言学生信息管理系统
时间: 2024-03-17 17:43:47 浏览: 27
好的,那我可以为您提供一个简单的学生信息管理系统的代码示例,供您参考。
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义学生信息结构体
struct student {
char name[20];
int age;
char gender[10];
char id[20];
};
// 定义全局变量,存储学生信息
struct student stu[100];
int count = 0;
// 声明函数
void add_student();
void delete_student();
void modify_student();
void search_student();
void display_all();
// 主函数
int main() {
int choice;
while (1) {
printf("\n\n学生信息管理系统\n");
printf("------------------\n");
printf("1. 添加学生信息\n");
printf("2. 删除学生信息\n");
printf("3. 修改学生信息\n");
printf("4. 查找学生信息\n");
printf("5. 显示所有学生信息\n");
printf("6. 退出\n");
printf("------------------\n");
printf("请选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
delete_student();
break;
case 3:
modify_student();
break;
case 4:
search_student();
break;
case 5:
display_all();
break;
case 6:
exit(0);
default:
printf("输入无效,请重新输入!");
break;
}
}
return 0;
}
// 添加学生信息
void add_student() {
printf("\n添加学生信息\n");
printf("------------------\n");
printf("请输入学生姓名:");
scanf("%s", stu[count].name);
printf("请输入学生年龄:");
scanf("%d", &stu[count].age);
printf("请输入学生性别:");
scanf("%s", stu[count].gender);
printf("请输入学生学号:");
scanf("%s", stu[count].id);
count++;
printf("添加成功!");
}
// 删除学生信息
void delete_student() {
char id[20];
int i, j;
printf("\n删除学生信息\n");
printf("------------------\n");
printf("请输入要删除的学生学号:");
scanf("%s", id);
for (i = 0; i < count; i++) {
if (strcmp(stu[i].id, id) == 0) {
for (j = i; j < count - 1; j++) {
stu[j] = stu[j + 1];
}
count--;
printf("删除成功!");
return;
}
}
printf("未找到该学生信息!");
}
// 修改学生信息
void modify_student() {
char id[20];
int i;
printf("\n修改学生信息\n");
printf("------------------\n");
printf("请输入要修改的学生学号:");
scanf("%s", id);
for (i = 0; i < count; i++) {
if (strcmp(stu[i].id, id) == 0) {
printf("请输入学生姓名:");
scanf("%s", stu[i].name);
printf("请输入学生年龄:");
scanf("%d", &stu[i].age);
printf("请输入学生性别:");
scanf("%s", stu[i].gender);
printf("修改成功!");
return;
}
}
printf("未找到该学生信息!");
}
// 查找学生信息
void search_student() {
char id[20];
int i;
printf("\n查找学生信息\n");
printf("------------------\n");
printf("请输入要查找的学生学号:");
scanf("%s", id);
for (i = 0; i < count; i++) {
if (strcmp(stu[i].id, id) == 0) {
printf("姓名:%s 年龄:%d 性别:%s 学号:%s\n", stu[i].name, stu[i].age, stu[i].gender, stu[i].id);
return;
}
}
printf("未找到该学生信息!");
}
// 显示所有学生信息
void display_all() {
int i;
printf("\n所有学生信息\n");
printf("------------------\n");
for (i = 0; i < count; i++) {
printf("姓名:%s 年龄:%d 性别:%s 学号:%s\n", stu[i].name, stu[i].age, stu[i].gender, stu[i].id);
}
}
```
这是一个比较简单的学生信息管理系统,包括添加、删除、修改、查找、显示所有学生信息等功能。您可以根据自己的需求进行修改和扩展。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)