news 2026/4/18 21:34:41

学生管理系统(单链表练习)

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
学生管理系统(单链表练习)

功能:

  1. 录入学生信息
  2. 打印学生信息
  3. 统计学生人数
  4. 查找学生信息
  5. 修改学生信息
  6. 删除学生信息
  7. 按成绩排序
  8. 退出系统
#include<stdio.h>#include<stdlib.h>#include<conio.h>//学生信息typedefstruct_Student{intstuNum;charname[20];intscore;}Student;//结点信息typedefstruct_Node{Student student;struct_Node*next;}Node;voidwelcome();voidinputStudent(Node*head);voidprintStudent(Node*head);voidcountStudent(Node*head);voidfindStudent(Node*head);voidsaveStudent(Node*head);voidloadStudent(Node*head);voidmodifyStudent(Node*head);voiddeleteStudent(Node*head);voidsortStudent(Node*head);intmain(){//创建头结点Node*head=(Node*)malloc(sizeof(Node));head->next=NULL;loadStudent(head);while(1){welcome();charc=_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("Bye Bye!\n");exit(0);break;default:printf("请重新输入\n");break;}}return0;}voidwelcome(){printf("*********************************\n");printf("*\t学生成绩管理系统\t*\n");printf("*********************************\n");printf("*\t请选择功能列表\t\t*\n");printf("*********************************\n");printf("*\t1.录入学生信息\t\t*\n");printf("*\t2.打印学生信息\t\t*\n");printf("*\t3.统计学生人数\t\t*\n");printf("*\t4.查找学生信息\t\t*\n");printf("*\t5.修改学生信息\t\t*\n");printf("*\t6.删除学生信息\t\t*\n");printf("*\t7.按成绩排序\t\t*\n");printf("*\t8.退出系统\t\t*\n");printf("*********************************\n");}voidinputStudent(Node*head){Node*fresh=(Node*)malloc(sizeof(Node));fresh->next=NULL;printf("请输入学生的学号,姓名,成绩 ");scanf("%d%s%d",&fresh->student.stuNum,fresh->student.name,&fresh->student.score);Node*move=head;while(move->next!=NULL){move=move->next;}//将学生插入到尾部move->next=fresh;saveStudent(head);//暂停程序system("pause");//清空控制台system("cls");}voidprintStudent(Node*head){Node*move=head->next;while(move!=NULL){printf("学号:%d 姓名:%s 成绩:%d\n",move->student.stuNum,move->student.name,move->student.score);move=move->next;}//暂停程序system("pause");//清空控制台system("cls");}voidcountStudent(Node*head){intcount=0;Node*move=head->next;while(move!=NULL){count++;move=move->next;}printf("学生的总人数为:%d\n",count);//暂停程序system("pause");//清空控制台system("cls");}voidfindStudent(Node*head){printf("请输入要查找的学生的学号: ");intstuNum;scanf("%d",&stuNum);Node*move=head->next;while(move!=NULL){if(stuNum==move->student.stuNum){printf("学号: %d 姓名:%s 成绩:%d\n",move->student.stuNum,move->student.name,move->student.score);//暂停程序system("pause");//清空控制台system("cls");return;}move=move->next;}printf("未找到学生信息\n");//暂停程序system("pause");//清空控制台system("cls");}voidsaveStudent(Node*head){FILE*file=fopen("./stu.info","w");Node*move=head->next;while(move!=NULL){if(fwrite(&move->student,sizeof(Student),1,file)!=1){printf("写入失败\n");return;}move=move->next;}fclose(file);}voidloadStudent(Node*head){FILE*file=fopen("./stu.info","r");if(!file){printf("没有学生文件,跳过读取\n");return;}Node*fresh=(Node*)malloc(sizeof(Node));fresh->next=NULL;Node*move=head;while(fread(&fresh->student,sizeof(Student),1,file)==1){move->next=fresh;move=fresh;fresh=(Node*)malloc(sizeof(Student));fresh->next=NULL;}free(fresh);fclose(file);printf("读取成功\n");}voidmodifyStudent(Node*head){printf("请输入要修改的学生的学号: ");intstuNum;scanf("%d",&stuNum);Node*move=head->next;while(move!=NULL){if(move->student.stuNum==stuNum){printf("请输入学生姓名,成绩\n");scanf("%s%d",move->student.name,&move->student.score);saveStudent(head);printf("修改成功\n");//暂停程序system("pause");//清空控制台system("cls");return;}move=move->next;}printf("未找到学生信息\n");//暂停程序system("pause");//清空控制台system("cls");}voiddeleteStudent(Node*head){printf("请输入要删除的学生学号 ");intstuNum=0;scanf("%d",&stuNum);Node*move=head;while(move->next!=NULL){if(move->next->student.stuNum==stuNum){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("未找到学生信息\n");//暂停程序system("pause");//清空控制台system("cls");}voidsortStudent(Node*head){Node*save=NULL;Node*move=NULL;for(Node*turn=head->next;turn->next!=NULL;turn=turn->next){for(move=head->next;move->next!=save;move=move->next){if(move->student.score>move->next->student.score){Student temp=move->student;move->student=move->next->student;move->next->student=temp;}}save=move;}printStudent(head);}
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/17 15:42:29

头歌实训-图论实战:从概念到最短路径的Python实现

1. 图论基础&#xff1a;从零理解数据结构 第一次接触图论时&#xff0c;我完全被各种术语搞晕了。直到在头歌实训平台反复练习后&#xff0c;才发现图论其实就像我们日常生活中的社交网络。想象一下微信好友关系&#xff1a;每个人是一个顶点&#xff0c;好友关系就是边&#…

作者头像 李华
网站建设 2026/4/17 15:42:17

intv_ai_mk11镜像免配置:开箱即用Web界面+独立venv环境部署详解

intv_ai_mk11镜像免配置&#xff1a;开箱即用Web界面独立venv环境部署详解 1. 快速了解intv_ai_mk11 intv_ai_mk11是一个基于Llama架构的中等规模文本生成模型&#xff0c;特别适合日常的文本处理任务。想象一下&#xff0c;它就像一个随时待命的文字助手&#xff0c;能帮你回…

作者头像 李华
网站建设 2026/4/19 17:51:08

DynamoDB 交易写操作的计费解析

引言 在使用 AWS DynamoDB 进行数据库操作时,计费是每个开发者都需要考虑的重要因素之一。特别是当我们使用 DynamoDB 进行交易写操作时,计费方式可能会直接影响应用程序的设计和成本。本文将详细探讨 DynamoDB 交易写操作的计费机制,并通过一个聊天应用的实例来说明其实际…

作者头像 李华
网站建设 2026/4/17 15:41:18

智能车竞赛别再花钱买内核了!手把手教你用龙芯2K0300+Linux 4.19配置PWM和编码器(附开源内核文件)

从零构建龙芯2K0300智能车竞赛内核&#xff1a;PWM与编码器配置实战指南 去年智能车竞赛现场调试时&#xff0c;我注意到隔壁赛道的队伍正手忙脚乱地重刷商业内核——他们的编码器突然失灵&#xff0c;而卖家提供的解决方案是"加钱升级VIP服务"。这场景让我意识到&am…

作者头像 李华
网站建设 2026/4/19 3:29:53

DDColor修复黑白照片:简单操作,效果惊艳实测

DDColor修复黑白照片&#xff1a;简单操作&#xff0c;效果惊艳实测 1. 老照片修复的新选择 看着家里泛黄的黑白老照片&#xff0c;你是否想过让它们重新焕发光彩&#xff1f;过去&#xff0c;这需要专业修图师花费数小时手工上色。而现在&#xff0c;借助DDColor技术&#x…

作者头像 李华
网站建设 2026/4/19 17:50:45

LGTV Companion 终极指南:如何让LG电视与电脑智能联动

LGTV Companion 终极指南&#xff1a;如何让LG电视与电脑智能联动 【免费下载链接】LGTVCompanion Power On and Off WebOS LG TVs together with your PC 项目地址: https://gitcode.com/gh_mirrors/lg/LGTVCompanion 你是否厌倦了每次使用电脑时都要手动开关电视&…

作者头像 李华