c语言实训学生成绩管理系统
时间: 2023-07-13 15:36:40 浏览: 65
学生成绩管理系统是C语言实训中常用的项目,可以帮助学生了解C语言的基本语法和数据结构。下面是一个简单的C语言学生成绩管理系统的实现:
1. 学生信息结构体定义
```
struct student {
char name[20]; // 学生姓名
int id; // 学生学号
float score; // 学生成绩
};
```
2. 添加学生信息函数
```
void add_student(struct student s[], int *count) {
printf("请输入学生姓名:");
scanf("%s", s[*count].name);
printf("请输入学生学号:");
scanf("%d", &s[*count].id);
printf("请输入学生成绩:");
scanf("%f", &s[*count].score);
(*count)++;
printf("添加成功!\n");
}
```
3. 查询学生信息函数
```
void query_student(struct student s[], int count) {
int id;
printf("请输入要查询的学生学号:");
scanf("%d", &id);
int i;
for (i = 0; i < count; i++) {
if (s[i].id == id) {
printf("姓名:%s,学号:%d,成绩:%f\n", s[i].name, s[i].id, s[i].score);
return;
}
}
printf("未找到该学生!\n");
}
```
4. 删除学生信息函数
```
void delete_student(struct student s[], int *count) {
int id;
printf("请输入要删除的学生学号:");
scanf("%d", &id);
int i;
for (i = 0; i < *count; i++) {
if (s[i].id == id) {
(*count)--;
for (; i < *count; i++) {
s[i] = s[i+1];
}
printf("删除成功!\n");
return;
}
}
printf("未找到该学生!\n");
}
```
5. 修改学生信息函数
```
void modify_student(struct student s[], int count) {
int id;
printf("请输入要修改的学生学号:");
scanf("%d", &id);
int i;
for (i = 0; i < count; i++) {
if (s[i].id == id) {
printf("请输入新的学生姓名:");
scanf("%s", s[i].name);
printf("请输入新的学生学号:");
scanf("%d", &s[i].id);
printf("请输入新的学生成绩:");
scanf("%f", &s[i].score);
printf("修改成功!\n");
return;
}
}
printf("未找到该学生!\n");
}
```
6. 显示所有学生信息函数
```
void show_all_students(struct student s[], int count) {
int i;
for (i = 0; i < count; i++) {
printf("姓名:%s,学号:%d,成绩:%f\n", s[i].name, s[i].id, s[i].score);
}
}
```
7. 主函数
```
int main() {
struct student students[100];
int count = 0;
int choice;
while (1) {
printf("1.添加学生信息\n2.查询学生信息\n3.删除学生信息\n4.修改学生信息\n5.显示所有学生信息\n6.退出\n");
printf("请选择操作:");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student(students, &count);
break;
case 2:
query_student(students, count);
break;
case 3:
delete_student(students, &count);
break;
case 4:
modify_student(students, count);
break;
case 5:
show_all_students(students, count);
break;
case 6:
printf("谢谢使用!\n");
return 0;
default:
printf("无效操作!\n");
break;
}
}
return 0;
}
```
以上是一个简单的C语言学生成绩管理系统的实现,可以根据需要进行修改和完善。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://img-home.csdnimg.cn/images/20210720083646.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)