700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > C语言版-学生信息管理系统(链表实现)

C语言版-学生信息管理系统(链表实现)

时间:2020-12-09 18:15:57

相关推荐

C语言版-学生信息管理系统(链表实现)

#include<stdio.h>#include<stdlib.h>#include<string.h>#define M 2#define N 4typedef 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;}}```

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。