学生成绩管理系统c语言代码
时间: 2023-07-31 14:11:44 浏览: 36
以下是一个简单的学生成绩管理系统的C语言代码,包括添加学生信息、修改学生信息、删除学生信息和查询学生信息等功能:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义学生结构体
typedef struct {
char name[20]; // 学生姓名
int id; // 学生学号
int score; // 学生成绩
} student;
// 定义全局变量,用于记录学生数量和学生信息数组
int count = 0;
student *students[100];
// 添加学生信息
void add_student() {
student *s = (student*) malloc(sizeof(student));
printf("请输入学生姓名:");
scanf("%s", s->name);
printf("请输入学生学号:");
scanf("%d", &s->id);
printf("请输入学生成绩:");
scanf("%d", &s->score);
students[count++] = s;
printf("学生信息添加成功!\n");
}
// 修改学生信息
void modify_student() {
int id, i;
printf("请输入要修改学生的学号:");
scanf("%d", &id);
for (i = 0; i < count; i++) {
if (students[i]->id == id) {
printf("请输入学生姓名:");
scanf("%s", students[i]->name);
printf("请输入学生成绩:");
scanf("%d", &students[i]->score);
printf("学生信息修改成功!\n");
return;
}
}
printf("未找到该学生信息!\n");
}
// 删除学生信息
void delete_student() {
int id, i, j;
printf("请输入要删除学生的学号:");
scanf("%d", &id);
for (i = 0; i < count; i++) {
if (students[i]->id == id) {
free(students[i]);
for (j = i; j < count - 1; j++) {
students[j] = students[j + 1];
}
count--;
printf("学生信息删除成功!\n");
return;
}
}
printf("未找到该学生信息!\n");
}
// 查询学生信息
void query_student() {
int id, i;
printf("请输入要查询学生的学号:");
scanf("%d", &id);
for (i = 0; i < count; i++) {
if (students[i]->id == id) {
printf("姓名:%s,学号:%d,成绩:%d\n", students[i]->name, students[i]->id, students[i]->score);
return;
}
}
printf("未找到该学生信息!\n");
}
// 显示所有学生信息
void show_all_students() {
int i;
printf("序号\t姓名\t学号\t成绩\n");
for (i = 0; i < count; i++) {
printf("%d\t%s\t%d\t%d\n", i + 1, students[i]->name, students[i]->id, students[i]->score);
}
}
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:
add_student();
break;
case 2:
modify_student();
break;
case 3:
delete_student();
break;
case 4:
query_student();
break;
case 5:
show_all_students();
break;
case 6:
printf("程序已退出!\n");
return 0;
default:
printf("输入有误,请重新选择操作!\n");
}
}
}
```
这个代码可以在控制台中运行,根据提示输入数字选择操作即可。注意,这个代码只是一个简单的示例,实际使用时还需要根据具体需求进行修改和完善。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://img-home.csdnimg.cn/images/20210720083646.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)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)