学生信息管理系统c语言代码
时间: 2023-08-01 14:07:19 浏览: 58
以下是一个简单的学生信息管理系统的C语言代码示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100 // 最大学生数
// 学生结构体
typedef struct {
char name[50];
int age;
char gender[10];
int id;
float score;
} Student;
// 学生数组
Student students[MAX_STUDENTS];
int studentCount = 0;
// 添加学生
void addStudent() {
if (studentCount >= MAX_STUDENTS) {
printf("学生已满,无法添加!\n");
return;
}
printf("请输入学生姓名:");
scanf("%s", students[studentCount].name);
printf("请输入学生年龄:");
scanf("%d", &students[studentCount].age);
printf("请输入学生性别:");
scanf("%s", students[studentCount].gender);
printf("请输入学生学号:");
scanf("%d", &students[studentCount].id);
printf("请输入学生成绩:");
scanf("%f", &students[studentCount].score);
studentCount++;
printf("学生添加成功!\n");
}
// 显示学生列表
void showStudentList() {
printf("序号\t姓名\t年龄\t性别\t学号\t成绩\n");
for (int i = 0; i < studentCount; i++) {
printf("%d\t%s\t%d\t%s\t%d\t%.2f\n", i + 1, students[i].name, students[i].age, students[i].gender, students[i].id, students[i].score);
}
}
// 查找学生
void searchStudent() {
int id;
printf("请输入学生学号:");
scanf("%d", &id);
for (int i = 0; i < studentCount; i++) {
if (students[i].id == id) {
printf("姓名:%s\n", students[i].name);
printf("年龄:%d\n", students[i].age);
printf("性别:%s\n", students[i].gender);
printf("学号:%d\n", students[i].id);
printf("成绩:%.2f\n", students[i].score);
return;
}
}
printf("未找到该学生!\n");
}
// 修改学生
void editStudent() {
int id;
printf("请输入学生学号:");
scanf("%d", &id);
for (int i = 0; i < studentCount; i++) {
if (students[i].id == id) {
printf("请输入学生姓名:");
scanf("%s", students[i].name);
printf("请输入学生年龄:");
scanf("%d", &students[i].age);
printf("请输入学生性别:");
scanf("%s", students[i].gender);
printf("请输入学生成绩:");
scanf("%f", &students[i].score);
printf("学生修改成功!\n");
return;
}
}
printf("未找到该学生!\n");
}
// 删除学生
void deleteStudent() {
int id;
printf("请输入学生学号:");
scanf("%d", &id);
for (int i = 0; i < studentCount; i++) {
if (students[i].id == id) {
// 将后面的学生前移
for (int j = i; j < studentCount - 1; j++) {
students[j] = students[j + 1];
}
studentCount--;
printf("学生删除成功!\n");
return;
}
}
printf("未找到该学生!\n");
}
// 主函数
int main() {
int choice;
while (1) {
printf("欢迎使用学生信息管理系统!\n");
printf("1. 添加学生\n");
printf("2. 显示学生列表\n");
printf("3. 查找学生\n");
printf("4. 修改学生\n");
printf("5. 删除学生\n");
printf("6. 退出系统\n");
printf("请选择功能:");
scanf("%d", &choice);
switch (choice) {
case 1:
addStudent();
break;
case 2:
showStudentList();
break;
case 3:
searchStudent();
break;
case 4:
editStudent();
break;
case 5:
deleteStudent();
break;
case 6:
printf("谢谢使用!\n");
exit(0);
default:
printf("无效的选择!\n");
break;
}
printf("\n");
}
return 0;
}
```
该代码实现了以下功能:
1. 添加学生
2. 显示学生列表
3. 查找学生
4. 修改学生
5. 删除学生
运行代码后,会显示一个菜单,提示用户选择功能,用户选择相应的功能后,程序会执行相应的操作。
该代码使用了结构体来存储学生信息,使用了数组来存储多个学生,使用了循环和条件语句来实现不同的功能。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.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)