C语言学生成绩信息管理系统
时间: 2023-12-26 09:05:24 浏览: 76
C语言学生成绩信息管理系统【结构体+文本】
以下是一个简单的C语言学生成绩信息管理系统的示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct student_information {
char name[15]; //姓名
char number[15]; //学号
int score[3]; //三科成绩
struct student_information *next;
} student_information;
// 初始化链表
student_information *initList() {
student_information *head;
head = (student_information *)malloc(sizeof(student_information));
head->next = NULL;
return head;
}
// 添加学生信息
void addStudent(student_information *head) {
int judge;
while (1) {
printf("是否继续输入成绩: 1(是)/0(否) ");
scanf("%d", &judge);
if (judge == 1) {
student_information *p;
p = (student_information *)malloc(sizeof(student_information));
printf("请输入学生姓名: ");
scanf("%s", p->name);
printf("请输入学生学号: ");
scanf("%s", p->number);
printf("请输入学生三科成绩: ");
scanf("%d %d %d", &p->score[0], &p->score[1], &p->score[2]);
if (!head->next) {
head->next = p;
p->next = NULL;
} else {
p->next = head->next;
head->next = p;
}
} else {
break;
}
}
}
// 查询学生信息
void searchStudent(student_information *head, char *number) {
student_information *p = head->next;
while (p) {
if (strcmp(p->number, number) == 0) {
printf("学生姓名: %s\n", p->name);
printf("学生学号: %s\n", p->number);
printf("学生三科成绩: %d %d %d\n", p->score[0], p->score[1], p->score[2]);
return;
}
p = p->next;
}
printf("未找到该学生信息\n");
}
// 修改学生信息
void modifyStudent(student_information *head, char *number) {
student_information *p = head->next;
while (p) {
if (strcmp(p->number, number) == 0) {
printf("请输入学生姓名: ");
scanf("%s", p->name);
printf("请输入学生学号: ");
scanf("%s", p->number);
printf("请输入学生三科成绩: ");
scanf("%d %d %d", &p->score[0], &p->score[1], &p->score[2]);
printf("修改成功\n");
return;
}
p = p->next;
}
printf("未找到该学生信息\n");
}
// 删除学生信息
void deleteStudent(student_information *head, char *number) {
student_information *p = head->next;
student_information *pre = head;
while (p) {
if (strcmp(p->number, number) == 0) {
pre->next = p->next;
free(p);
printf("删除成功\n");
return;
}
pre = p;
p = p->next;
}
printf("未找到该学生信息\n");
}
// 打印所有学生信息
void printAllStudents(student_information *head) {
student_information *p = head->next;
while (p) {
printf("学生姓名: %s\n", p->name);
printf("学生学号: %s\n", p->number);
printf("学生三科成绩: %d %d %d\n", p->score[0], p->score[1], p->score[2]);
p = p->next;
}
}
int main() {
student_information *head = initList();
int choice;
char number[15];
while (1) {
printf("请选择操作:\n");
printf("1. 添加学生信息\n");
printf("2. 查询学生信息\n");
printf("3. 修改学生信息\n");
printf("4. 删除学生信息\n");
printf("5. 打印所有学生信息\n");
printf("0. 退出\n");
scanf("%d", &choice);
switch (choice) {
case 1:
addStudent(head);
break;
case 2:
printf("请输入要查询的学生学号: ");
scanf("%s", number);
searchStudent(head, number);
break;
case 3:
printf("请输入要修改的学生学号: ");
scanf("%s", number);
modifyStudent(head, number);
break;
case 4:
printf("请输入要删除的学生学号: ");
scanf("%s", number);
deleteStudent(head, number);
break;
case 5:
printAllStudents(head);
break;
case 0:
return 0;
default:
printf("无效的选择\n");
break;
}
}
return 0;
}
```
阅读全文