C语言版-学生信息管理系统(链表实现)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define M 2
#define N 4
typedef struct score//定义成绩结构体
{int math;//数学int c_language;//c语言int english;//英语double ave;//平均分int total_sum;//总分
}SCORE;typedef struct stu
{char id[20];//学号char name [10];//姓名char sex[20];//性别char pro[20];//专业int year;//入学年份SCORE stu_score;//学生成绩char stu_lesson[N][50];//学生选课
}STU;typedef struct list
{STU data;struct list *next;
}LIST;//创建链表结构体
LIST *Creat_List(STU s[]);//链表的创建
int Stu_Entry(STU stu[]);//学生信息的录入
int Score_Entry(STU score[]);//学生成绩的录入
void S_score(LIST*head);//利用链表进行成绩的输出
void infor_show(LIST*head);//利用链表对学生信息进行输出
void S_sort(STU s[],int flag);//利用结构体进行排序
SCORE Score_search(char *s,LIST *p,int flag);//成绩的查询
LIST *Delet_Score(char*s,LIST*tr,int flag);//成绩的删除
LIST *Delet_infor(char*st,LIST *ht,int flag);//学生记录的删除
LIST *Re_score(char *sr,SCORE R_score,LIST *h,int flag);//成绩修改
void Show_infor(char *S_s,LIST*h,int flag);//学生信息的查询
int Elect_les(STU lesson[]);//学生选课
LIST* Insert_infor(LIST *in_infor );//学生信息的添加
void main()
{printf("\t\t\t欢迎进入学生信息管理系统\n");system("color 9");int choice;//输入你的选择char user[23];//输入用户名char key[20];//输入密码STU stu[M];//结构体数组 LIST *head;//链表的头结点head=Creat_List(stu);printf("请输入用户名:\n");scanf("%s",user);printf("请输入密码:\n");scanf("%s",key);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("* 9---成绩删除 *\n");printf("* 10--信息查询 *\n");printf("* 11--信息输出 *\n");printf("* 12--学生选课 *\n");printf("* 13--退出程序 *\n");printf("*******************************\n");if(strcmp(user,"admin")==0&&strcmp(key,"123456")==0){printf("请输入你的选择:\n");while(scanf("%d",&choice)!=EOF){system("cls");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("* 9---成绩修改 *\n");printf("* 10--信息查询 *\n");printf("* 11--信息输出 *\n");printf("* 12--学生选课 *\n");printf("* 13--退出程序 *\n");printf("*******************************\n");switch(choice){case 1:{printf("请录入学生的信息:\n");if(Stu_Entry(stu))printf("信息录入完成\n");elseprintf("信息录入失败\n");system("pause");break;}case 2:{printf("请录入每位学生对应的成绩:\n");if(Score_Entry(stu))printf("学生成绩录入完成\n");elseprintf("学生成绩录入失败\n");system("pause");break;}case 3:{printf("成绩的输出为:\n");S_score(Creat_List(stu));system("pause");break;}case 4:{ int choice;printf("请输入排序的方式(1-平均分排序 2-总分排序)\n");scanf("%d",&choice);printf("成绩排序的结果为:\n");S_sort(stu,choice);S_score(Creat_List(stu));system("pause");break;system("pause");break;}case 5:{SCORE result;char name_search[20];char id_search[20];int choice;printf("请输入查询方式(1-学号查询 2-姓名查询):\n"); scanf("%d",&choice);switch(choice){case 1: { printf("请输入需要查询的学生的学号:\n");scanf("%s",id_search);printf("学号为%s学生的数学 c语言 英语成绩 总分以及平均分为:\n",id_search);result= Score_search(id_search,Creat_List(stu),1);printf("查询的结果为:\n");printf("%d %d %d %d %.1lf\n",result.math,result.c_language,result.english,result.total_sum,result.ave);break;}case 2:{printf("请输入需要查询的学生的姓名:\n");scanf("%s",name_search);printf("学生%s的数学 c语言 英语成绩 总分以及平均分为:\n",name_search);result= Score_search(id_search,Creat_List(stu),2);printf("查询的结果为:\n");printf("%d %d %d %d %.1lf\n",result.math,result.c_language,result.english,result.total_sum,result.ave);break;} }system("pause");break;}case 6: {char id[20];//需要查询学号 char name[20];//需要查询的姓名 int choice;//输入你的选择 printf("请输入查询方式(1-学号查询 2-姓名查询):\n"); scanf("%d",&choice);switch(choice){case 1: { printf("请输入要删除成绩学生的学号:\n");scanf("%s",id);if(Delet_Score(id,Creat_List(stu),1)!=NULL){printf("成绩删除成功!\n");S_score(Delet_Score(id,Creat_List(stu),1));}else printf("成绩删除失败!\n");break;}case 2:{printf("请输入要删除信息学生的姓名:\n");scanf("%s",name);printf("信息删除后的结果为:\n");if(Delet_Score(name,Creat_List(stu),2)!=NULL){printf("成绩删除成功!\n");S_score(Delet_Score(name,Creat_List(stu),2));}elseprintf("成绩删除失败!\n");break;} }system("pause");break;}case 7:{printf("插入后的结果为:\n");S_score(Insert_infor(Creat_List(stu)));system("pause");break;}case 8:{ printf("学生信息的删除:\n");LIST *q;char id[20];char name[20];int choice;printf("请输入查询方式(1-学号查询 2-姓名查询):\n"); scanf("%d",&choice);switch(choice){case 1: { printf("请输入要删除信息学生的学号:\n");scanf("%s",id);q=Delet_infor(id,Creat_List(stu),1);if(q==NULL)printf("信息删除失败\n");else{ printf("信息删除后的结果为:\n");infor_show(q);}break;}case 2:{printf("请输入要删除信息学生的姓名:\n");scanf("%s",name);printf("信息删除后的结果为:\n");if(q==NULL)printf("信息删除失败!\n");else{ printf("信息删除后的结果为:\n");q=Delet_infor(name,Creat_List(stu),2);}infor_show(q);break;} }system("pause");break;}case 9:{ int choice;SCORE re_score;int sum=0; char id[20];char name[20];printf("请输入要修改的英语 c语言 数学:\n");scanf("%d %d %d",&re_score.english,&re_score.c_language, &re_score.math); sum=re_score.english+re_score.c_language+re_score.math; re_score.ave=sum/3.0;printf("请输入查询方式(1-学号查询 2-姓名查询):\n"); scanf("%d",&choice);switch(choice){case 1: { printf("请输入要修改学生的学号:\n");scanf("%s",id);printf("成绩修改后的结果为:\n");S_score(Re_score(id,re_score,Creat_List(stu),choice));break;}case 2:{printf("请输入要修改学生的姓名:\n");scanf("%s",name);printf("成绩修改后的结果为:\n");S_score(Re_score(name,re_score,Creat_List(stu),choice));break;} }system("pause");break;}case 10:{char id[20];char name[20];int choice;printf("请输入查询方式(1-学号查询 2-姓名查询):\n"); scanf("%d",&choice);switch(choice){case 1: { printf("请输入要查询学生的学号:\n");scanf("%s",id);Show_infor(id,Creat_List(stu),choice);break;}case 2:{printf("请输入要查询学生的姓名:\n");scanf("%s",name);Show_infor(id,Creat_List(stu),choice);break;} }system("pause");break;}case 11: {printf("学生信息的输出结果为:\n");infor_show(Creat_List(stu));system("pause");break;}case 12:{ system("cls");//system("pause");printf("请输入选修课程中的四门课程:\n");if( Elect_les(stu))printf("学生选课成功!\n");elseprintf("学生选课失败!\n");break;}case 13: {printf("系统已经安全退出!!!");exit(0);system("pause");break;}default:{printf("输入的选择有误,请重新输入你的选择:\n");system("pause");break;}}printf("可以选择继续录入也可以按ctrl+z退出\n");}}else{system("cls");printf("输入用户名或者密码错误,请退出后重新输入!\n");}
}
LIST *Creat_List(STU *s)//PS:链表的建立
{//尾插法进行建立链表 LIST *h,*p;LIST*tail; int i;h=(LIST*)(malloc)(sizeof(LIST));if(h==NULL)return h;elsetail=h;for(i=0;i<M;i++){p=(LIST*)malloc(sizeof(LIST));if(p==NULL)return NULL;else{p->data=s[i];tail->next=p;tail=p;tail->next=NULL;}}//头插法进行创建链表/* LIST*h,*p;int i;h=(LIST*)malloc(sizeof(LIST));if(h==NULL)return NULL;elseh->next=NULL;for(i=0;i<M;i++){p=(LIST*)malloc(sizeof(LIST));if(p==NULL)return NULL;else{p->data=s[i];p->next=h->next;h->next=p;}}*/return h;
}
int Stu_Entry(STU stu[M])//PS:学生信息录入函数的封装
{int i;for(i=0;i<M;i++){printf("输入第%d个学生学号 姓名 性别 专业 入学年份: \n", i + 1);scanf("%s %s %s %s %d", stu[i].id, stu[i].name, stu[i].sex,&stu[i].pro, &stu[i].year);stu[i].stu_score.math=0;stu[i].stu_score.c_language=0;stu[i].stu_score.english=0;}if(i==M)return 1;elsereturn 0;
}
int Score_Entry(STU score[])//PS:成绩的输入的函数的封装
{int i;int s=0;STU *p=score;for(i=0;i<M;i++){printf("请输入%d位学生的数学 c语言 英语:\n",i+1);scanf("%d %d %d",&score[i].stu_score.math,&score[i].stu_score.c_language,&score[i].stu_score.english);getchar();s=score[i].stu_score.math+score[i].stu_score.c_language+score[i].stu_score.english;score[i].stu_score.total_sum=s;score[i].stu_score.ave=s/3.0;}if(i==M)return 1;elsereturn 0;
}void S_score(LIST*head)//PS:成绩输出函数的封装
{LIST *p;int count=1;p=head->next;if(p==NULL){printf("链表发生错误!!!\n");return;}else{printf("HEAD->\n");while(p!=NULL){printf("%d-学号:%s学生的数学 c语言 英语成绩 总分以及平均分为:\n",count,p->data.id);printf("%d %d %d %d %.1lf\n",p->data.stu_score.math,p->data.stu_score.c_language,p->data.stu_score.english,p->data.stu_score.total_sum,p->data.stu_score.ave);p=p->next;count++;}printf("->END\n");}
}void S_sort(STU s[],int flag)//PS:成绩的排序函数的封装 利用结构体
{int i,j;int k;STU t;if(flag==1){for(i=0;i<M-1;i++)//选择排序{ k=i;for(j=i;j<M;j++)if(s[k].stu_score.ave<s[j].stu_score.ave)k=j;if(k!=i){t=s[k];s[k]=s[i];s[i]=t;}}}if(flag==2){for(i=0;i<M-1;i++)//选择排序{ k=i;for(j=i;j<M;j++)if(s[k].stu_score.total_sum<s[j].stu_score.total_sum)k=j;if(k!=i){t=s[k];s[k]=s[i];s[i]=t;}}}
}
SCORE Score_search(char *s,LIST *h,int flag)//PS:成绩的查询函数的封装
{LIST *p;p=h;if(p==NULL){printf("链表有误!\n");}else{/*while(p!=NULL){if(strcmp(p->data.id,s)==0){break;}p=p->next;}return (p->data.stu_score);*/if(strcmp(p->data.id,s)==0&&flag==1)return (p->data.stu_score);else if(strcmp(p->data.name,s)==0&&flag==2){return (p->data.stu_score);}elsereturn (Score_search(s,p->next,flag));//递归}}
LIST* Delet_Score(char* s,LIST *tr,int flag)//PS:删除成绩函数的封装
{LIST *p;p=tr->next;if(p==NULL){printf("链表有误,成绩删除失败!\n");return 0;}else{ if(flag==1){while(p!=NULL){if(strcmp(p->data.id,s)==0){p->data.stu_score.c_language=0;p->data.stu_score.english=0;p->data.stu_score.math=0;p->data.stu_score.total_sum=0;p->data.stu_score.ave=0.0;break;}p=p->next;}}if(flag==2){while(p!=NULL){if(strcmp(p->data.id,s)==0){p->data.stu_score.c_language=0;p->data.stu_score.english=0;p->data.stu_score.math=0;p->data.stu_score.ave=0.0;break;}p=p->next;}}if(p==NULL)return NULL;elsereturn tr;}
}
LIST* Delet_infor(char *st,LIST *ht,int flag)//PS:学生信息删除函数的封装
{LIST*p;LIST*tem;p=ht->next;if(p==NULL){printf("链表错误!\n");return NULL;}else{while(p!=NULL){if(strcmp(p->data.id,st)==0&&flag==1){tem=p;break;}if(strcmp(p->data.name,st)==0&&flag==2){tem=p;break;}p=p->next;}while(strcmp(p->data.id,st)!=0&& p->next!=NULL)//PS:循环查找要删除的节点{tem=p;p=p->next;}if( strcmp(p->data.id,st)==0)//找到了一个节点的num和num相等{if(p == ht->next)//找到的节点是头节点后面的一个节点{ht->next= p->next;}else{tem->next=p->next;}return ht;}elsereturn ht=NULL;}}
LIST *Re_score(char *sr,SCORE R_score,LIST *h,int flag)//PS:成绩修改函数的封装
{//LIST *q;//q=h;LIST *p;p=h->next;if(p==NULL){printf("链表发生错误,成绩修改失败!\n");return p;}else{while(p!=NULL){ if(strcmp(p->data.id,sr)==0&&flag==1){break;}if(strcmp(p->data.id,sr)==0&&flag==2){break;}p=p->next;}p->data.stu_score= R_score;}return h;
}
void infor_show(LIST*h)//PS:学生信息全部输出函数的封装
{LIST *p;int i;p=h->next;if(p==NULL)printf("链表发生错误!!!\n");else{while(p!=NULL){ printf("学号%s的学生信息:\n",p->data.id);printf("姓名:%s 性别:%s 专业:%s 入学年份:%d\n",p->data.name,p->data.sex,p->data.pro,p->data.year);printf("该学生的选择的选修课为:\n");for(i=0;i<N;i++)printf("%s\t",p->data.stu_lesson[i]);p=p->next;printf("\n");}}
}
void Show_infor(char *S_s,LIST*h,int flag)//PS:信息查询输出函数的封装
{LIST*p;p=h->next;int i;if(p==NULL)printf("链表出现错误!!!\n");else{while(p!=NULL){if(strcmp(p->data.id,S_s)==0&&flag==1)break;if(strcmp(p->data.id,S_s)==0&&flag==2)break;p=p->next;}printf("学生的姓名 性别 专业 入学年份\n");printf("%s %s %s %d\n",p->data.name,p->data.sex,p->data.pro,p->data.year);printf("该学生的选择的选修课为:\n");for(i=0;i<N;i++)printf("%s\t",p->data.stu_lesson[i]);}
}
int Elect_les(STU lesson[])//PS:选修课的录入
{int i,j;printf("*******************************\n");printf("* 1---语言文学 *\n");printf("* 2---人文地理 *\n");printf("* 3---思想政治 *\n");printf("* 4---口才艺术 *\n");printf("* 5---经济管理 *\n");printf("* 6---国际贸易 *\n");printf("* 7---职场礼仪 *\n");printf("*******************************\n");for(i=0;i<M;i++){printf("请输入第%d位学生的选修的课程:\n",i+1);for(j=0;j<N;j++){scanf("%s",lesson[i].stu_lesson[j]);getchar();}}if(i==M)return 1;elsereturn 0;}
LIST* Insert_infor(LIST *in_infor)//PS:学生信息添加函数的封装
{LIST *p;LIST *st;LIST *q;int s=0;double ave=0;st=in_infor->next;p=(LIST*)malloc(sizeof (LIST));printf("请输入要填加的学生的学号 姓名 性别 专业 入学年份:\n");scanf("%s %s %s %s %d", p->data.id, p->data.name, p->data.sex,p->data.pro,&p->data.year);printf("请输入要填加的学生的成绩:\n");scanf("%d %d %d",&p->data.stu_score.math,&p->data.stu_score.english,&p->data.stu_score.c_language);s=p->data.stu_score.c_language+p->data.stu_score.english+p->data.stu_score.math;p->data.stu_score.ave=s/3.0;//st=in_infor->next;if(st==NULL){printf("链表发生错误!\n");return NULL;}else{/*in_infor->next=p;p->next=st;return in_infor;*/while(st!=NULL){if(st->data.stu_score.ave<p->data.stu_score.ave)break;st=st->next;}q=in_infor;while(q->next!=st)q=q->next;q->next=p;p->next=st;return in_infor;}
}```
C语言版-学生信息管理系统(链表实现)相关推荐
- 赶紧进来看看--用C语言实现学生信息管理系统(1.0静态版)
本文介绍了用C语言实现学生信息管理系统设计,主要包括对学生信息增删查改.分类统计.排序等功能,文章最后有全部源码展示- C语言实现学生信息管理系统--1.0静态版 一.学生信息管理系统介绍 二.实现学 ...
- 赶紧进来看看---C语言实现学生信息管理系统(3.0文件存储版)
本文主要介绍了将学生信息管理系统改造为文件存储版本- 主要涉及文件操作函数–将学生信息导入文件和从文件读取学生信息到程序中,从而达到数据持久化的效果 文章最后有源码展示 学生信息管理系统1.0静态版- ...
- 学生管理系统c语言的作用,C语言实现学生信息管理系统(文件版)
本文实例为大家分享了C语言实现学生信息管理系统的具体代码,供大家参考,具体内容如下 下面是我自己用写的学生信息管理系统,为了增加数据的利用率,分为学生端和教师端,同时实现账号密码登录,以文件的形式将其 ...
- c语言 版本号,C语言版本学生信息管理系统
仍然有一些小bug,后续会发布OC完善版的图书馆管理系统,欢迎批评指正. #include void menu_choose(); typedef struct { int Id; int age; ...
- [置顶]完美简版学生信息管理系统(附有源码)管理系统
简版学生信息管理系统 目前为止找到的简版系统中最新.最全的java类管理系统 点击进入简版系统 如果无法直接连接,请进入: https://blog.csdn.net/weixin_43419816/ ...
- c语言饭卡管理系统链表文件,C语言《学生信息管理系统》链表+文件操作
今天带来的是一个链表版本的<学生信息管理系统>,功能包括:添加.显示.查询.删除.保存.读取,等功能模块,链表是C语言的进阶内容,希望大家好好学习,这里的代码可能会有一些瑕疵,希望大家提供 ...
- C语言实现学生信息管理系统(附原码)
本人的C语言学习完后,用所学的知识自己实现了一个学生管理系统,新手一个,代码还有待完善,欢迎大家在评论区指出错误! 一.流程图 二.函数的目录 三.程序介绍 1.主要功能:添加学生信息.打印学生信息. ...
- [源码和文档分享]基于C语言的学生信息管理系统
一 需求分析 利用c语言的链表或结构体数组实现学生信息的管理,编写有登录界面的学生信息管理系统,可以实现学生信息的录入,显示,删除,排序,统计,文件读写等功能. 二 概要设计 系统功能模块结构如下图所 ...
- C语言:学生信息管理系统
文章目录 前言 一.思路 1.流程图 2.代码 (1)登录界面 (2)功能框架 ①基本的函数框架 ②改进 二.分布实现 1.定义结构体 2.文件读取 3.输出学生信息 (1)功能实现 (2)输出界面 ...
最新文章
- 动感效果的TAB选项卡 jquery 插件
- 用于高保真自然图像合成的大规模GAN训练(Large Scale GAN Training For High Fidelity Natural Images)论文 pdf
- SharePoint 补丁
- 共享经济时代,中小企业该如何逆风翻盘?
- 古代大臣上朝时手里拿的是什么东西
- Swift5版本以上自定义回调函数报错
- Windows 下git 与 github 相关联
- Python基础100题
- android 多线程编程
- Spring MVC 中使用AOP 进行统一日志管理--XML配置实现
- Linux进阶之Git分布式版本控制系统篇
- spring教程笔记3
- (转)被AI改变的风投模式:数据驱动使效率提高10倍
- 软件测试—如何建立软件测试管理体系?
- 【Java代码笔记】
- 微录音--Android通话录音(vluyin-callrecorder)一款安卓通话录音软件
- JavaWeb课堂笔记
- 百度Uditor富文本编辑器使用以及图片不显示问题
- 雪豹安装光盘 苹果mac 下载
- 美国黄岩超级计算机,飓风预测 揭秘最快气候研究“黄石”超算