请你用C语言写一个学生成绩管的代码包括查询、添加、删除、功能
时间: 2023-06-01 09:02:46 浏览: 84
用C语言写的学生成绩管理系统
抱歉,我是一个语言模型,无法提供本地代码。以下是一个简单的学生成绩管理系统的伪代码,供您参考:
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义结构体,用于存储学生信息
struct Student {
char name[20];
int id;
float score;
struct Student *next;
};
// 定义全局变量,用于记录链表头节点和节点数量
struct Student *head = NULL;
int count = 0;
// 添加学生信息
void add_student() {
struct Student *new_student = (struct Student*)malloc(sizeof(struct Student));
printf("请输入学生姓名:");
scanf("%s", new_student->name);
printf("请输入学生学号:");
scanf("%d", &new_student->id);
printf("请输入学生成绩:");
scanf("%f", &new_student->score);
new_student->next = head;
head = new_student;
count++;
printf("学生信息添加成功!\n");
}
// 查询学生信息
void search_student() {
int id;
printf("请输入要查询的学生学号:");
scanf("%d", &id);
struct Student *p = head;
while (p != NULL) {
if (p->id == id) {
printf("学生姓名:%s\n", p->name);
printf("学生学号:%d\n", p->id);
printf("学生成绩:%.1f\n", p->score);
return;
}
p = p->next;
}
printf("未找到该学生的信息!\n");
}
// 删除学生信息
void delete_student() {
int id;
printf("请输入要删除的学生学号:");
scanf("%d", &id);
struct Student *p = head;
struct Student *prev = NULL;
while (p != NULL) {
if (p->id == id) {
if (prev == NULL) {
head = p->next;
} else {
prev->next = p->next;
}
free(p);
count--;
printf("学生信息删除成功!\n");
return;
}
prev = p;
p = p->next;
}
printf("未找到该学生的信息!\n");
}
// 显示所有学生信息
void show_all_students() {
if (count == 0) {
printf("暂无学生信息!\n");
return;
}
struct Student *p = head;
printf("学生总数:%d\n", count);
while (p != NULL) {
printf("学生姓名:%s\n", p->name);
printf("学生学号:%d\n", p->id);
printf("学生成绩:%.1f\n", p->score);
p = p->next;
}
}
int main() {
int choice;
while (1) {
printf("\n");
printf("学生成绩管理系统\n");
printf("1. 添加学生信息\n");
printf("2. 查询学生信息\n");
printf("3. 删除学生信息\n");
printf("4. 显示所有学生信息\n");
printf("5. 退出程序\n");
printf("请输入您的选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
search_student();
break;
case 3:
delete_student();
break;
case 4:
show_all_students();
break;
case 5:
printf("程序已退出!\n");
exit(0);
default:
printf("无效的选择!\n");
}
}
return 0;
}
```
阅读全文