C语言学生管理系统.docx

上传人:小飞机 文档编号:3155117 上传时间:2023-03-11 格式:DOCX 页数:14 大小:39.19KB
返回 下载 相关 举报
C语言学生管理系统.docx_第1页
第1页 / 共14页
C语言学生管理系统.docx_第2页
第2页 / 共14页
C语言学生管理系统.docx_第3页
第3页 / 共14页
C语言学生管理系统.docx_第4页
第4页 / 共14页
C语言学生管理系统.docx_第5页
第5页 / 共14页
亲,该文档总共14页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《C语言学生管理系统.docx》由会员分享,可在线阅读,更多相关《C语言学生管理系统.docx(14页珍藏版)》请在三一办公上搜索。

1、C语言学生管理系统学生管理系统 #define_CRT_SECURE_NO_WARNINGS #include #include #include voidAppendNode(longlong studentID,char studentName10,char studentSex4,int score4);/添加数据 voidDisplayNode(structlink*head);/显示数据 voidInsertNode(longlong studentID,char studentName10,char studentSex4,int score4);/插入一条数据;按总分的从大到小排

2、序 voidInsertNodeNumber(longlong studentID,char studentName10,char studentSex4,int score4);/按学号的从小到大排序 voidNumberSorting(int flag);/按从大到小对数据进行排序;1、对总分进行排序,2、对学号进行排序 voidDeleteNodeID;/输入学号删除 voidDeleteNodeName;/输入学号删除 voidDeleteMemory(structlink*head);/删除聊表所占用的内存; voidSave;/保存数据 voidOpen;/打开数据 voidFin

3、dID;/按学号查找学生 voidFindName;/按姓名查找学生; voidMenu; typedefstructstudent longlongstudentID; charstudentName10; charstudentSex4; intscore4; STU; structlink ; structlink*head=NULL;/保存输入的学生信息数据 structlink*head1=NULL;/保存排序后的学生信息数据 intmain longlongstudentID; charstudentName10; charstudentSex4; intscore4;/定义要输入

4、学生信息的变量; charc; STUstudent; structlink*next; intmenu;/保存要进行的选项; Open; while(1) system(pause); Menu; printf(请输入要进行的操作:); scanf(%d,&menu); switch(menu) case0:exit(0); break; case1: printf(请输入Y或y来添加数据n); scanf( %c,&c); while(c=y|c=Y) printf(请输入学生学号:); scanf(%lld,&studentID); printf(请输入学生姓名:); scanf(%s,

5、&studentName); printf(请输入学生性别:); scanf(%s,&studentSex); inti=0; printf(请分别输入学生四门课的成绩:); for(i=0;istudent.studentID=studentID; strcpy(p-student.studentName,studentName); while(pr-next!=NULL) pr-next=p; pr=pr-next; head=p; printf(申请内存失败); return; strcpy(p-student.studentSex,studentSex); p-student.scor

6、e0=score0; p-student.score1=score1; p-student.score2=score2; p-student.score3=score3; p-next=NULL; return; voidNumberSorting(intflag) structlink*p=head; structlink*p1=head1; intsum=0; if(p=NULL) while(p!=NULL) switch(flag) printf(没有数据,无法排序); return; case1: InsertNode(p-student.studentID,p-student.st

7、udentName,p-student.studentSex,p-student.score); break; case2: InsertNodeNumber(p-student.studentID,p-student.studentName,p-student.studentSex,p-student.score); voidDisplayNode(structlink*head) structlink*p=head; if(p=NULL) DisplayNode(head1); break; default: p=p-next; printf(程序异常,请重试!); break; prin

8、tf(%lld,p-student.studentID); printf(%10s,p-student.studentName); printf(%5s,p-student.studentSex); printf(n); DisplayNode(p-next); inti=0; for(i=0;istudent.scorei); return; voidDeleteMemory(structlink*head) structlink*p=head,*pr=NULL; while(p!=NULL) pr=p; p=p-next; free(pr); voidInsertNodeNumber(lo

9、nglongstudentID,charstudentName10,charstudentSex4,intscore4) structlink*pr=head1,*p=head1,*temp=NULL; p=(structlink*)malloc(sizeof(structlink); if(p=NULL) p-next=NULL; p-student.studentID=studentID; strcpy(p-student.studentName,studentName); strcpy(p-student.studentSex,studentSex); p-student.score0=

10、score0; p-student.score1=score1; p-student.score2=score2; printf(内存申请失败); return; p-student.score3=score3; if(head1=NULL) else while(pr-student.studentIDnext!=NULL) if(pr-student.studentID=studentID) if(pr=head1) else pr=temp; p-next=head1; head1=p; temp=pr; pr=pr-next; head1=p; p-next=pr-next; pr-n

11、ext=p; else pr-next=p; return; voidInsertNode(longlongstudentID,charstudentName10,charstudentSex4,intscore4) structlink*pr=head1,*p=head1,*temp=NULL; intsum,sum1; p=(structlink*)malloc(sizeof(structlink); if(p=NULL) printf(内存申请失败); return; p-next=NULL; p-student.studentID=studentID; strcpy(p-student

12、.studentName,studentName); strcpy(p-student.studentSex,studentSex); p-student.score0=score0; p-student.score1=score1; p-student.score2=score2; p-student.score3=score3; sum=p-student.score0+p-student.score1+p-student.score2+p-student.score3; sum1=pr-student.score0+pr-student.score1+pr-student.scorif(

13、head1=NULL) else head1=p; e2+pr-student.score3; while(sum1sum&pr-next!=NULL) temp=pr; pr=pr-next; sum1=pr-student.score0+pr-student.score1+pr-student.score2+pr-student.score3; if(sum1next=pr-next; pr-next=p; p-next=head1; head1=p; pr-next=p; return; voidDeleteNodeID/输入学号删除 structlink*p=head,*pr=head

14、; longlongstudentID=0; if(head=NULL) printf(请输入你要删除的学生的学号); scanf(%s,studentID); while(studentID!=p-student.studentID&p-next!=NULL) pr=p; printf(对不起,没有数据可以删除); return; p=p-next; if(studentID=p-student.studentID) else return; printf(你要查找的这个数据未找到); if(p=head) else free(p); pr-next=p-next; head=p-next;

15、 voidDeleteNodeName/输入姓名删除 structlink*p=head,*pr=head; charstudentName10=; if(head=NULL) printf(请输入你要删除的学生的姓名:); scanf(%s,studentName); while(0!=strcmp(studentName,p-student.studentName)&p-next!=Nprintf(对不起,没有数据可以删除); return; ULL) if(0=strcmp(studentName,p-student.studentName) if(p=head) else pr-nex

16、t=p-next; head=p-next; pr=p; p=p-next; free(p); else return; printf(你要查找的这个数据未找到); voidSave/保存链表中的数据 fprintf(fp,%20lld%10s%5s%4d%4d%4d%4d,p-student.studentID,p-FILE*fp; structlink*p=head; if(fp=fopen(demo.txt,w)=NULL) while(p!=NULL) printf(打开文件失败); return; student.studentName,p-student.studentSex, p

17、-student.score0, p-student.score1, p-student.score2, p-student.score3); p=p-next; fclose(fp); return; voidOpen/将文件中获得的数据写入到链表中 longlongstudentID; charstudentName10; charstudentSex4; intscore4; FILE*fp; charc; if(fp=fopen(demo.txt,r)=NULL) printf(文件打开失败); return; while(c=fgetc(fp)!=EOF) fclose(fp); f

18、scanf(fp,%20lld,&studentID); fscanf(fp,%10s,studentName); fscanf(fp,%5s,studentSex); fscanf(fp,%4d,&score0); fscanf(fp,%4d,&score1); fscanf(fp,%4d,&score2); fscanf(fp,%4d,&score3); AppendNode(studentID,studentName,studentSex,score); voidFindID structlink*p=head; longlongstudentID=0; if(head=NULL) pr

19、intf(没有数据查找); return; printf(请输入你要查找的学生的学号:); scanf(%lld,&studentID); while(studentID!=p-student.studentID&p-next!=NULL) if(studentID=studentID) else printf(没有你要查找的数据); printf(%lld,p-student.studentID); printf(%10s,p-student.studentName); printf(%5s,p-student.studentSex); inti=0; for(i=0;istudent.sc

20、orei); p=p-next; return; voidFindName structlink*p=head; charstudentName10=; if(head=NULL) printf(请输入你要查找的学生的姓名:); scanf(%s,studentName); while(0!=strcmp(studentName,p-student.studentName)&p-next!=Nprintf(没有数据查找); return; ULL) if(0=strcmp(studentName,p-student.studentName) printf(%lld,p-student.stud

21、entID); printf(%10s,p-student.studentName); p=p-next; printf(%5s,p-student.studentSex); inti=0; for(i=0;istudent.scorei); else return; printf(没有你要查找的数据); voidMenu system(cls);/清平操作; printf(nnnnn);/输入回车,形成格式; printf(tt|.学生管理系统.|n);/ printf(tt|t 0.退出。 |n);/“/t”水平制表,相当于一个tab键; printf(tt|t 1.添加学生成绩信息! |n); printf(tt|t 2.查找学生(按学号)信息! |n); printf(tt|t 3.查找学生(按姓名)信息! |n); printf(tt|t 4.删除学生成绩(按学号)信息! |n); printf(tt|t 5.删除学生成绩(按姓名)信息! |n); printf(tt|t 6.按总分排序! |n); printf(tt|t 7.按学号排序! |n); printf(tt|.学生管理系统.|n);/

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号