本人无偿奉献学生管理系统的所有代码,包括.h头文件和.c文件,要源码私信,或者评论,希望点个关注。可以完整运行。
介绍一下这个系统,该系统包括八个功能:
printf("1.录入学生信息\n");
printf("2.打印学生信息\n");
printf("3.统计学生人数\n");
printf("4.查找学生信息\n");
printf("5.修改学生信息\n");
printf("6.删除学生信息\n");
printf("7.按成绩排序\n");
printf("8.退出系统\n");
并且可以存储学生的个人信息,以及进行连续的存储、查找、删除。
.c文件
#include "Student_system.h"
int main()
{
Node* head = malloc(sizeof(Node));
head->next = NULL;
loadstudent(head);
while (1)
{
welcome();
char c = _getch();
switch (c)
{
case'1':
inputStudent(head);
break;
case'2':
printstudent(head);
break;
case'3':
countstudent(head);
break;
case'4':
findstudent(head);
break;
case'5':
modifystudent(head);
break;
case'6':
deletestudent(head);
break;
case'7':
sortstudent(head);
break;
case'8':
system("cls");
printf("欢迎下次使用\n");
exit(0);
break;
default:
break;
}
}
return 0;
}
void welcome()
{
printf("**************************\n");
printf("*****学生成绩管理系统*****\n");
printf("**************************\n");
printf("********请选择功能********\n");
printf("1.录入学生信息\n");
printf("2.打印学生信息\n");
printf("3.统计学生人数\n");
printf("4.查找学生信息\n");
printf("5.修改学生信息\n");
printf("6.删除学生信息\n");
printf("7.按成绩排序\n");
printf("8.退出系统\n");
printf("**************************\n");
}
void inputStudent(Node* head)
{
Node* fresh = (Node*)malloc(sizeof(Node));
if (fresh == NULL) {
printf("内存分配失败,无法录入新学生信息。\n");
return; // 避免对 NULL 指针的解引用
}
fresh->next = NULL;
printf("请输入学生的学号、姓名、成绩");
scanf_s("%d", &fresh->student.stunum);
scanf_s("%s",fresh->student.name,20);
scanf_s("%d", &fresh->student.score);
Node* move = head;
while (move->next != NULL)
{
move = move->next;
}
move->next = fresh;
savestudent(head);
system("pause");
system("cls");
}
void printstudent(Node* head)
{
Node* move = head->next;
while (move != NULL)
{
printf("\n学号:%d 姓名:%s 成绩:%d\n", move->student.stunum, move->student.name, move->student.score);
printf("\n");
move = move->next;
}
}
void countstudent(Node* head)
{
int count = 0;
Node* move = head->next;
while (move != NULL)
{
count++;
move = move->next;
}
printf("学生的总人数为:%d\n", count);
system("pause");
system("cls");
}
void findstudent(Node* head)
{
printf("请输入学生的学号:");
int num;
scanf_s("%d", &num);
Node* move = head->next;
while (move != NULL)
{
if (num == move->student.stunum)
{
printf("\n学号:%d 姓名:%s 成绩:%d\n", move->student.stunum, move->student.name, move->student.score);
return;
}
move = move->next;
}
printf("未找到学生信息:\n");
system("pause");
system("cls");
}
void savestudent(Node* head)
{
FILE* file = fopen("./stu.info", "w");
if (file == NULL)
{
printf("打开失败");
}
Node* move = head->next;
while (move != NULL)
{
if (fwrite(&move->student, sizeof(Student), 1, file) != 1)
{
printf("写入失败\n");
return;
}
move = move->next;
}
fclose(file);
}
void loadstudent(Node* head)
{
FILE* file = fopen("./stu.info", "r");
if (!file)
{
printf("没有学生文件,跳过读取\n");
return;
}
Node* fresh = malloc(sizeof(Node));
fresh->next = NULL;
Node* move = head;
while (fread(&fresh->student, sizeof(Student), 1, file) == 1)
{
move->next = fresh;
move = fresh;
fresh = malloc(sizeof(Node));
fresh->next = NULL;
}
free(fresh);
fclose(file);
printf("读取成功\n");
}
void modifystudent(Node* head)
{
printf("请输入要修改的学生信息的学号:");
int num;
scanf("%d", &num);
Node* move = head->next;
while(move != NULL)
{
if (move->student.stunum == num)
{
printf("请输入学生的姓名、成绩\n");
scanf_s("%s", move->student.name, 20);
scanf_s("%d", &move->student.score);
savestudent(head);
printf("修改成功\n");
system("pause");
system("cls");
return;
}
move = move->next;
}
printf("未找到学生信息");
system("pause");
system("cls");
}
void deletestudent(Node* head)
{
printf("请输入学生的学号:");
int num;
scanf_s("%d", &num);
Node* move = head;
while (move->next != NULL)
{
if (move->next->student.stunum == num)
{
Node* tmp = move->next;
move->next = move->next->next;
free(tmp);
tmp = NULL;
savestudent(head);
printf("删除成功\n");
system("pause");
system("cls");
return;
}
move = move->next;
}
printf("未找到学生信息");
system("pause");
system("cls");
}
void sortstudent(Node* head)
{
for (Node* turn = head->next; turn->next != NULL; turn = turn->next)
{
for (Node* move = head->next; move->next != NULL; move = move->next)
{
if (move->student.score > move->next->student.score)
{
Student temp = move->student;
move->student = move->next->student;
move->next->student = temp;
}
}
}
printstudent(head);
}
.h文件
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
typedef struct _Student
{
int stunum;
char name[20];
int score;
}Student;
typedef struct _Node
{
Student student;
struct _Node* next;
}Node;
void welcome();
void inputStudent(Node* head);
void printstudent(Node* head);
void countstudent(Node* head);
void findstudent(Node* head);
void savestudent(Node* head);
void loadstudent(Node* head);
void modifystudent(Node* head);
void deletestudent(Node* head);
void sortstudent(Node* head);
结果