用C语言编写一个学生管理系统
时间: 2023-08-23 16:03:47 浏览: 50
好的,学生管理系统可以包括以下几个模块:
1.添加学生信息
2.查找学生信息
3.修改学生信息
4.删除学生信息
5.显示所有学生信息
下面是一个简单的 C 语言代码示例:
```c
#include <stdio.h>
#include <string.h>
struct student {
int id;
char name[20];
int age;
};
void add_student(struct student *s, int *count)
{
printf("请输入学生信息(学号 姓名 年龄):");
scanf("%d %s %d", &s[*count].id, s[*count].name, &s[*count].age);
(*count)++;
printf("添加成功!\n");
}
void find_student(struct student *s, int count)
{
int id, i;
printf("请输入要查找的学生学号:");
scanf("%d", &id);
for (i = 0; i < count; i++) {
if (s[i].id == id) {
printf("学号:%d,姓名:%s,年龄:%d\n", s[i].id, s[i].name, s[i].age);
return;
}
}
printf("未找到该学生!\n");
}
void modify_student(struct student *s, int count)
{
int id, i;
printf("请输入要修改的学生学号:");
scanf("%d", &id);
for (i = 0; i < count; i++) {
if (s[i].id == id) {
printf("请输入修改后的学生信息(学号 姓名 年龄):");
scanf("%d %s %d", &s[i].id, s[i].name, &s[i].age);
printf("修改成功!\n");
return;
}
}
printf("未找到该学生!\n");
}
void delete_student(struct student *s, int *count)
{
int id, i, j;
printf("请输入要删除的学生学号:");
scanf("%d", &id);
for (i = 0; i < *count; i++) {
if (s[i].id == id) {
for (j = i; j < *count - 1; j++) {
s[j] = s[j + 1];
}
(*count)--;
printf("删除成功!\n");
return;
}
}
printf("未找到该学生!\n");
}
void display_student(struct student *s, int count)
{
int i;
printf("学号\t姓名\t年龄\n");
for (i = 0; i < count; i++) {
printf("%d\t%s\t%d\n", s[i].id, s[i].name, s[i].age);
}
}
int main()
{
struct student s[100];
int choice, count = 0;
while (1) {
printf("请选择操作:\n");
printf("1.添加学生信息\n");
printf("2.查找学生信息\n");
printf("3.修改学生信息\n");
printf("4.删除学生信息\n");
printf("5.显示所有学生信息\n");
printf("6.退出\n");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student(s, &count);
break;
case 2:
find_student(s, count);
break;
case 3:
modify_student(s, count);
break;
case 4:
delete_student(s, &count);
break;
case 5:
display_student(s, count);
break;
case 6:
return 0;
default:
printf("输入错误,请重新输入!\n");
}
}
}
```
这是一个基本的学生管理系统实现,可以根据需要进行更改和扩展。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)