简易学生成绩管理系统
时间: 2023-12-22 09:29:03 浏览: 28
以下是一个简易的学生成绩管理系统的示例代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义学生结构体
typedef struct Student {
char name[20];
int score;
struct Student* next;
} Node;
Node* g_pHead = NULL; // 头节点指针
// 添加学生信息
void AddStudent() {
Node* newNode = (Node*)malloc(sizeof(Node));
printf("请输入学生姓名:");
scanf("%s", newNode->name);
printf("请输入学生成绩:");
scanf("%d", &(newNode->score));
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 SearchStudent() {
char searchName[20];
printf("请输入要查找的学生姓名:");
scanf("%s", searchName);
Node* p = g_pHead;
while (p != NULL) {
if (strcmp(p->name, searchName) == 0) {
printf("学生姓名:%s\n", p->name);
printf("学生成绩:%d\n\n", p->score);
system("pause");
system("cls");
return;
}
p = p->next;
}
printf("未找到该学生信息!\n\n");
system("pause");
system("cls");
}
int main() {
int choice;
while (1) {
printf("1. 添加学生信息\n"); printf("2. 统计所有学生人数\n");
printf("3. 查找学生信息\n");
printf("4. 退出\n");
printf("请输入操作选项:");
scanf("%d", &choice);
switch (choice) {
case 1:
AddStudent();
break;
case 2:
CountStudent();
break;
case 3:
SearchStudent();
break;
case 4:
return 0;
default:
printf("无效的选项!\n\n");
system("pause");
system("cls");
break;
}
}
}
```