C语言课设学生信息管理系统_第1页
C语言课设学生信息管理系统_第2页
C语言课设学生信息管理系统_第3页
免费预览已结束,剩余12页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、流程图 :开始显示菜单输入 ch 的值ch=?1.2.3.4.5.6.7.8.9.非调调调调调调调调调法0用用用用用用用用用选项creat()dele()add()sort()save()load()display()函函modify()search()函函函函数函数数函函数数数数数数结束全局变量struct studchar name20;long num;int age;char sex;int score3;char tele12;struct stud *next;子程序1.creat() 函数功能:创建链表,提示输入学生信息,储存到链表中,录入完成后输入y 继续,输入n 停止,返回主

2、菜单2.display()函数功能:显示当前已经存入链表的信息3.dele()函数功能:删除链表中学生信息,可按姓名或学号删除4.add() 函数功能:按学号插入学生信息5.modify() 函数功能:修改链表中学生信息6.search()函数功能:查找学生信息,可按学号或姓名查找7.sort()函数功能:对信息进行排序,可实现分别对三门成绩排序8.save()函数功能:将链表中的数据保存到指定文件9.load() 函数功能:将指定文件中已有的数据读入链表源程序#include<stdio.h>#include<string.h>#include<stdlib.h

3、>#include<conio.h>struct studchar name20;long num;int age;char sex;int score3;char tele12;struct stud *next;main()struct stud *head;struct stud *creat(void);void display(struct stud *head);struct stud *dele(struct stud *head);struct stud *add(struct stud *head);struct stud *modify(struct st

4、ud *head);void search(struct stud *head);void save(struct stud *head);struct stud *sort(struct stud *head);void save(struct stud *head);struct stud *load();char ch;head=NULL;for(;) clrscr(); /*清屏函数 */printf( “nnttWelcometostudentinformationmanagementsystem”);printf( “nnt*”);printf( “nttt1:Enter the

5、information ”);printf( “nttt2:List the information ”);printf( “nttt3:Delete the information ”);printf( “nttt4:Add the information ”);printf( “nttt5:Modify the information”);printf( “nttt6:Search the information ”);printf( “nttt7:Sort the information ”);printf( “nttt8:Save the information ”);printf(

6、“nttt9:Load the information ”);printf( “nttt0:Exit“);printf( “ntttEnter your choice: ”);fflush(stdin);ch=getchar();getchar();switch(ch)case 1:head=creat();break;case 2:display(head);system(“pause”);break;case 3:head=dele(head);system(“pause”);break;case 4:head=add(head);system(“pause”);break;case 5:

7、head=modify(head);system(“pause”);break;case 6:search(head);system(“pause”);break;case 7:head=sort(head);system(“pause”);break;case 8:save(head);system(“pause”);break;case 9:head=load();break;case 0:return;break;default :clrscr();printf( “nt Error!Please check your inputnn ”);system(“pause”);struct

8、stud *creat(void)/*链表的创建 */struct stud *head,*p1;char ch;clrscr();head=NULL;p1=(struct stud *)malloc(sizeof(struct stud);printf( “tenter name:”);gets(p1->name); printf( “tenter number: ”);scanf(“%ld ”,&p1->num);printf( “tenter age:”);scanf(“%d ”,&p1->age);printf( “tenter sex:”);fflu

9、sh(stdin);scanf(“%c”,&p1->sex);printf( “tenter Math score: ”);scanf(“%d ”,&p1->score0);printf( “tenter English score:”);scanf(“%d ”,&p1->score1);printf( “tenter C score:”);scanf(“%d ”,&p1->score2);printf( “tenter telephone number:”);fflush(stdin); gets(p1->tele);head=p

10、1;p1->next=NULL;do printf(“ntDO YOU WANT TO CONTINUE?Y or N? ”);printf(“ntEnter your choise: ”);fflush(stdin); ch=getchar(); clrscr(); if(ch= y|ch=Y )head=add(head);else if(ch!=N &&ch!= n) printf(“ ntError !Please check your input” );ch= y ;while(ch= y |ch= Y );return(head);struct stud *d

11、ele(struct stud *head)/*链表的删除 */struct stud *p1,*p2;int choose;long delnum;char name20;clrscr();printf(“ nttChoose the way you want” );printf(“ nt1: According to namen“ );printf(“ nt2: According to numn” );printf(“ ntEnter your choice:” );scanf( “ %d” ,&choose);fflush(stdin);if(choose=1)printf(“

12、 nt Enter the name:” );gets(name); if(head=NULL)printf(“tnNo information !n ”);return(head); p1=head;while(strcmp(name,p1->name)!=0&&p1->next!=NULL)p2=p1;p1=p1->next;if(strcmp(name,p1->name)=0)if(p1=head)head=p1->next;else p2->next=p1->next;printf(“ t Delete Successed !n

13、n” );else printf(“ t Not been find!nn” );return(head);else if(choose=2)printf(“ ntEnter the number:”);scanf( “ %ld” ,&delnum);if(head=NULL)printf( “nNoinformation!n ”);return(head);p1=head;while(delnum!=p1->num&&p1->next!=NULL)p2=p1;p1=p1->next;if(delnum=p1->num)if(p1=head)he

14、ad=p1->next;else p2->next=p1->next;printf(“ t Delete Successed !nn” );else printf(“ t Not been find!n” );return(head);else printf( “nt Error!Please check your inputnn ”);return(head);void display(struct stud *head)struct stud *p;p=head;clrscr();if(head=NULL)printf(“ nt No informationnn”);el

15、seprintf(“ nametnumbertagetsextMathtEnglishtCttelephonenumbern ” );doprintf( “%st%ldt%dt%ct%dt%dt%dt%sn ”,p->name,p->num,p->age,p->sex,p->score 0,p->score1,p->score2,p->tele);p=p->next;while(p!=NULL);struct stud *add(struct stud *head)/*链表的插入 */struct stud *p1,*p2,*p0;p0=(

16、struct stud *)malloc(sizeof(struct stud);clrscr();printf( “nttInput the information:”);printf( “nttname:”);fflush(stdin);gets(p0->name);printf(“ ttnumber:” );scanf( “ %ld” ,&p0->num);printf(“ ttage:” );scanf( “ %d” ,&p0->age);printf(“ ttsex:” );fflush(stdin);scanf( “ %c” ,&p0-&g

17、t;sex);printf(“ ttMath score:”);scanf( “ %d” ,&p0->score0);printf(“ ttEnglish score:”);scanf( “ %d” ,&p0->score1);printf(“ ttC score:” );scanf( “ %d” ,&p0->score2);printf(“ tttelephone number:” );fflush(stdin);gets(p0->tele);p1=head;if(head=NULL)head=p0;p0->next=NULL;elsew

18、hile(p0->num>p1->num)p2=p1,p1=p1->next;if(p0->num<=p1->num)if(head=p1)head=p0;else p2->next=p0;p0->next=p1;elsep1->next=p0;p0->next=NULL;return(head);struct stud *modify(struct stud *head)/*链表的修改 */struct stud *p1,*p2,*p0;clrscr();printf(“ ntInput the student s name:

19、 ” );p0=(struct stud *)malloc(sizeof(struct stud);fflush(stdin);gets(p0->name);if(head=NULL)printf(“nNoinformation!nn ”);return(head);p1=head;while(strcmp(p0->name,p1->name)!=0&&p1->next!=NULL)p2=p1;p1=p1->next;if(strcmp(p0->name,p1->name)=0)printf(“ nametnumbertagetsext

20、MathtEnglishtCttelephone numbern” );printf( “%st%ldt%dt%ct%dt%dt%dt%sn”,p1->name,p1->num,p1->age,p1->sex,p1->score0,p1->score1,p1->score2,p1->tele);if(p1=head)head=p1->next;else p2->next=p1->next;printf( “tNewinformation:number: ”);scanf(“%ld ”,&p0->num);print

21、f( “tttage:”); scanf(“%d ”,&p0->age);printf( “tttsex:”);fflush(stdin); scanf(“%c ”,&p0->sex);printf( “tttMath score:”);scanf(“%d ”,&p1->score0); printf( “tttEnglishscore:”); scanf(“%d ”,&p1->score1);printf( “tttCscore:”);scanf(“%d ”,&p1->score2);printf( “ttttelepho

22、nenumber: ”); fflush(stdin); gets(p0->tele); p1=head; if(head=NULL)head=p0;p0->next=NULL;elsewhile(p0->num>p1->num)p2=p1;p1=p1->next;if(p0->num<=p1->num)if(head=p1)head=p0;else p2->next=p0;p0->next=p1;elsep1->next=p0;p0->next=NULL;printf(“ Modify Successed !nne

23、lse printf(“ Not been find!nn”);”);return(head);void search(struct stud *head)/*查询链表 */struct stud *p;int choose;long num;char name20;clrscr();printf(“ nttChoose the way you want” );printf(“ nt1: According to namen“ );printf(“ nt2: According to numn” );printf(“ nt Enter your choice:”);scanf( “ %d” ,

24、&choose);fflush(stdin);if(choose=1)printf(“ nt enter the name:” );gets(name);if(head=NULL)printf(“tnNo information !nn ”);elsep=head;while(strcmp(name,p->name)!=0&&p->next!=NULL)p=p->next;if(strcmp(name,p->name)=0)printf(“ nametnumbertagetsextMathtEnglishtCttelephone numbern”

25、 );printf( “%st%ldt%dt%ct%dt%dt%dt%sn”,p->name,p->num,p->age,p->sex,p->score0,p->score1,p->score2,p->tele);else printf(“ Not been find!nn” );else if(choose=2)printf(“ nt Enter the number:”);scanf( “ %ld” ,&num);if(head=NULL)printf(“ nNo information!n” );elsep=head;while(n

26、um!=p->num&&p->next!=NULL)p=p->next;if(num=p->num)printf(“ nametnumbertagetsextMathtEnglishtCttelephone numbern” );printf( “%st%ldt%dt%ct%dt%dt%dt%sn”,p->name,p->num,p->age,p->sex,p->score0,p->score1,p->score2,p->tele);else printf(“ t Not been find!n” );el

27、se printf(“ nt Error!Please check your inputnn” );struct stud *sort(struct stud *head)struct stud *first;struct stud *t;struct stud *p;struct stud *q;int ch;clrscr();printf(“ nttChoose the way you want” );printf(“ nt1: According to Math:n” );printf(“ nt2: According to Englishn” );printf(“ nt3: Accor

28、ding to Cn” );printf(“ ntEnter your choice:” );scanf(“ %d” ,&ch);first = head->next;head->next = NULL;while (first != NULL)for(t=first, q=head; (q!=NULL) && (q->scorech-1>t->scorech-1); p=q, q=q->next);first = first->next;if (q = head)head = t;elsep->next = t;t-&g

29、t;next = q;printf( “ nttSuccess !n return head;” );void save(struct stud *head)/*保存链表FILE *fp;struct stud *p;char filename20;printf(“ nninput the filename:“ );fflush(stdin);gets(filename);if(fp=fopen(filename,” w” )=NULL)printf(“ Save file %s error ! Type it again.nnexit(0);p=head;*/” ,filename);whi

30、le(p!=NULL) fprintf(fp,” %st ” ,p->name);fprintf(fp,” %ldt ” ,p->num);fprintf(fp,” %dt ” ,p->age);fprintf(fp,” %ct ” ,p->sex);fprintf(fp,” %dt ” ,p->score0);fprintf(fp,” %dt ” ,p->score1);fprintf(fp,” %dt ” ,p->score2);fprintf(fp,” %stn ” ,p->tele);p=p->next;printf(“ nttSu

31、ccess !n” );fclose(fp);struct stud *load()/*链表的导入 */FILE *fp;char filename20;struct stud *head,*p1,*p2;printf(“ nninput the filename:“ );fflush(stdin);gets(filename);if(fp=fopen(filename,” r ” )=NULL)printf(“ Load file %s error ! Type it again.nn” ,filename);exit(0);if(!feof(fp)head=(struct stud *) malloc(sizeof(struct stud);fscanf(fp,” %st ” ,&head->name);fscanf(fp,” %

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论