c语言简单的学生成绩管理系统
时间: 2024-01-03 21:23:07 浏览: 43
以下是一个简单的C语言学生成绩管理系统的示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义学生结构体
typedef struct {
char name[20];
int score;
} Student;
// 定义链表节点结构体
typedef struct Node {
Student data;
struct Node* next;
} Node;
// 全局变量,链表头节点
Node* g_pHead = NULL;
// 添加学生信息
void AddStudent() {
Student stu;
printf("请输入学生姓名:");
scanf("%s", stu.name);
printf("请输入学生成绩:");
scanf("%d", &stu.score);
// 创建新节点
Node* newNode = (Node*)malloc(sizeof(Node));
newNode->data = stu;
newNode->next = NULL;
// 将新节点插入链表尾部
if (g_pHead == NULL) {
g_pHead = newNode;
} else {
Node* p = g_pHead;
while (p->next != NULL) {
p = p->next;
}
p->next = newNode;
}
printf("添加成功!\n\n");
system("pause");
system("cls");
}
// 统计所有学生人数
void CountStudent() {
int countStu = 0;
Node* p = g_pHead;
while (p != NULL) {
countStu++;
p = p->next;
}
printf("学生总人数:%d\n\n", countStu);
system("pause");
system("cls");
}
// 查找学生信息
void FindStudent() {
char name[20];
printf("请输入要查找的学生姓名:");
scanf("%s", name);
Node* p = g_pHead;
while (p != NULL) {
if (strcmp(p->data.name, name) == 0) {
printf("学生姓名:%s\n", p->data.name);
printf("学生成绩:%d\n\n", p->data.score);
system("pause");
system("cls");
return;
}
p = p->next;
}
printf("未找到该学生信息!\n\n");
system("pause");
system("cls");
}
int main() {
int choice;
while (1) {
printf("学生成绩管理系统\n");
printf("1. 添加学生信息\n");
printf("2. 统计所有学生人数\n");
printf("3. 查找学生信息\n");
printf("0. 退出\n");
printf("请输入您的选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
AddStudent();
break;
case 2:
CountStudent();
break;
case 3:
FindStudent();
break;
case 0:
printf("感谢使用!\n");
return 0;
default:
printf("输入有误,请重新输入!\n\n");
system("pause");
system("cls");
break;
}
}
}
```