C语言实现学生成绩管理系统
时间: 2023-12-31 10:24:58 浏览: 91
c语言实现学生成绩系统管理
C语言实现学生成绩管理系统的示例代码如下:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义学生结构体
typedef struct Student {
char name[20];
int score;
struct Student* next;
} Student;
// 全局变量,链表头指针
Student* g_pHead = NULL;
// 添加学生信息
void AddStudent() {
Student* newStudent = (Student*)malloc(sizeof(Student));
printf("请输入学生姓名:");
scanf("%s", newStudent->name);
printf("请输入学生成绩:");
scanf("%d", &(newStudent->score));
newStudent->next = NULL;
if (g_pHead == NULL) {
g_pHead = newStudent;
} else {
Student* p = g_pHead;
while (p->next != NULL) {
p = p->next;
}
p->next = newStudent;
}
printf("添加成功!\n\n");
system("pause");
system("cls");
}
// 统计所有学生人数
void CountStudent() {
int countStu = 0;
Student* 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);
Student* 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("学生成绩管理系统\n");
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:
exit(0);
default:
printf("输入有误,请重新输入!\n\n");
system("pause");
system("cls");
break;
}
}
return 0;
}
```
阅读全文