《C语言课程设计报告学生宿舍管理系统.doc》由会员分享,可在线阅读,更多相关《C语言课程设计报告学生宿舍管理系统.doc(38页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、- .程序设计工程训练报告学生宿舍管理系统课程名称 程序设计工程训练姓 名院系 信息科学与技术学院专业班级学 号指导教师教务处制- . 可修编.目 录1 需求分析12 系统总框图和功能模块说明22.1 系统总框图。22.2 功能模块说明32.3 程序总体框架43 系统设计103.1 主要构造体103.2主要功能函数104 调试情况114.1输入密码进入程序114.2主界面114.2.1输入学生信息114.2.2输出学生信息124.2.3更新学生信息124.2.4查询学生信息134.2.5排序134.2.6统计学生信息145 设计总结146 源程序清单15. 1 需求分析 输入正确密码后进入系统
2、,用read_message()函数先读取文件容,再在do while循环中用switch语句进展选择选一进入输入模块;选二进入输出模块;选三进入更新模块,在更新模块中又包含了三个小的模块:删除,修改,插入;选四进入查询模块,在查询模块中可以根据信息中的学号,XX,宿舍,楼层,楼号来进展查询;选五进入排序模块,在排序模块中可以根据学号,宿舍,楼层,楼号进展排序;选六进入统计模块,可以根据宿舍,楼层,楼号进展统计。)退出程序时,对信息进展保存,以便下次调用。2 系统总框图和功能模块说明2.1 系统总框图1输入函数input_message()2输出函数output_message()3.读函数r
3、ead_message()a).删除函数del_message()4.更新模块 b).修改函数revise_message() c)插入函数insert_message()a).按XX查询inquire_name()主函数5.查询模块 b).按学号查询inquire_num()c).按宿舍查询(inquire_dormitary()d).按楼层查询(inquire_floor()e).按宿舍楼查询(inquire_building() 6.排序模块 a).按学号排序(sort_num() b).按宿舍排序(sort_dormitary() c).按楼层排序(sort_floor() d).按宿
4、舍楼排序(sort_building()7.统计模块 a).按学号统计(count_num()b).按楼层统计(count_floor()c).按楼号统计(count_building()8保存信息(save_message()9退 出 2.2 功能模块说明1输入函数:用来录入数据和有关信息。2输出函数:用来输出录入的相关信息。3. 读函数:将文件中的数据读入。4更新模块:对以存信息进展更新.有以下几个选项:(1)删除函数:用来删除已离校的学生信息。(2)修改函数:用来修改改变宿舍的学生信息。(3)插入函数:用来插入新同学的宿舍信息。5查询模块:输入一项信息,可以得到存入的整条信息,具体有以下
5、: (1)按XX查询:输入学生XX,可得到整条学生信息。 (2)按学号查询:输入学生学号,可得到整条学生信息。 (3)按宿舍查询:输入宿舍号,可得到所有住在该宿舍号中的学生的所有信息。 (4)按楼层查询:输入楼层数后,可得到所有住在该层的学生信息。 (5)按宿舍楼查询:输入宿舍楼数,可得到所有住在该楼的学生信息。6排序模块:用来对录入的信息进展整理,使其排列有规律性。(1) 按学号排序:把输入的学号从小到大进展排序。(2) 按宿舍排序:把输入的宿舍从小到大进展排序。(3) 按楼层排序:把输入的楼层从小到大进展排序。(4) 按宿舍楼排序:把输入的宿舍楼从小到大进展排序。7统计模块:用来把录入的信
6、息进展统计,使使用者清楚明了。(1) 按宿舍统计:输入要统计的宿舍号,把这个宿舍里的所有成员输出,并显示在这个宿舍里的总人数。(2) 按楼层统计:输入要统计的楼层,把所有住在这个楼层上的学生信息输出,并显示总人数。(3) 按楼号统计:输入要统计的楼号,把所有住在该楼的学生信息输出,并显示总人数。8保存信息:对信息进展保存,使下次翻开时还存在。9退出系统。2.3 程序总体框架主函数流程图:开场 N输入密码Y读函数输入choice进入输入模块Choice 1 Y进入输出模块Choice 2N YN 进入更新模块Choice 3 YN进入查询模块Choice 4 YN 进入排序模块Choice 5读
7、函数 Y进入统计模块Choice 6N YN退出Choice 0 Y保存函数完毕修改模块流程图:开场输入学号输入choicechoice=1?输入修改后num 是 否输入修改后namechoice=2? 是 否输入修改后sexchoice=3? 是 否输入修改后agechoice=4? 是 否输入修改后majorchoice=5? 是Choice=6?输入修改后grade 否 是 否是Choice=7?输入修改后class 否 是Choice=8?输入修改后building否输入修改后floor是Choice=9?否Choice=10?输入修改后dormiatry是输出修改后信息完毕查询模块流
8、程图: 开场输入choiceInquire_namechoice=1? 是 否Inquire_numchoice=2? 是否 是Inquire_dormitarychoice=3? 否 Inquire_floorchoice=4? 是 否choice=5?Inquire_building 是 否choice=0? 是完毕更新模块流程图: 开场输入choiceoutput_message(h)del_message(h)choice=1? 是 否output_message(h)revise_message()choice=2? 是否 是output_message(h)insert_messa
9、ge(h);choice=3?choice=0? 是完毕删除模块流程图:开场输入nump0=hp=p0-nextp-num=nump0-next=p-next;free(p); 是 否p0=p;p=p-next; p=p-next;完毕 否按XX查询流程图: 开场输入namep0=hstrcmp(p0-name,name)?=0 是输出p0 否p0=p0-next 完毕按学号、宿舍号、楼层、宿舍楼的流程图类似于按XX查询的流程图排序模块流程图: 开场输入choiceoutput (h)sort_num()choice=1? 是 否output (h)sort_dormitary()choice
10、=2? 是否 是choice=3?sort_floor()output (h) 否 choice=4?sort_building()output (h) 是 否choice=0? 是完毕统计模块流程图: 开场输入choicecount_dormitary()choice=1? 是 否count_floor()choice=2? 是否 是count_building()choice=3?choice=0? 是完毕3 系统设计3.1 主要构造体struct stud int num; char name10; char sex8; int age; char major18; int grade;
11、int classes; int building; int floor; int dormitary;struct stud *next; ;3.2主要功能函数input_message()/*输入模块*/read_message()/*读取信息*/output_message(struct stud *p)/*输出模块*/del_message(struct stud *h)/*删除学生信息*/revise_message()/*修改学生信息*/insert_message(struct stud *h)/*插入学生信息*/renew_message()/*更新模块*/inquire_na
12、me()/*按XX查询*/inquire_num()/*按学号查询*/inquire_dormitary()/*按宿舍号查询*/inquire_floor()/*按楼层查询*/inquire_building()/*按宿舍楼查询*/inquire_message()/*查询模块*/sort_num()/*按学号排序*/sort_dormitary()/*按宿舍排序*/sort_floor()/*按楼层排序*/sort_building()/*按宿舍楼排序*/output(struct stud *p)/*用于输出排序的模块*/sort_message()/*排序模块*/count_floor(
13、)/*按楼层统计*/count_building()/*按宿舍楼统计*/count_message()/*统计模块*/save_message(struct stud *h)/*保存信息*/4 调试情况4.1输入密码进入程序4.2主界面4.2.1输入学生信息4.2.1.1输入一共有多少个学生信息4.2.1.2完成一个学生信息登记4.2.2输出学生信息4.2.3更新学生信息可如图:修改王安的性别4.2.4查询学生信息可如图:按宿舍楼查询4.2.5排序4.2.6统计学生信息如图:按楼层统计该程序中可能还存在一些小问题,比方有的时候它会主动清屏,有的时候不会。并且我在编译的过程中发现自己存在好多毛病
14、,有粗心了等,不注意细节,其实自己也知道细节决定成败,以后我会注意。5 设计总结 通过两周的编程,我完成了学生宿舍管理这个小系统。进一步理解并掌握了C 语言中的精华指针和键表。程序可以流畅运行,实现对数据的录入、修改、插入、删除、排序、查询、统计等根本功能。程序开场时从文件中读取数据,完毕时对新数据或更新的数据进展保存,以便下次再次调用。 在编程中也不是一帆风顺的,开场时由于对C语言的许多知识点都遗忘了,导致编程过程中相当吃力,经过一两天的适应后,模块根本上编的得心应手。但当我编写读数据这个模块时遇到了一点问题,程序总是读出一些乱码,并不是我先前存入的数据。经过指导教师耐心的指点下,终于解决了
15、这个问题。这次高级语言程序设计,不仅稳固了我所学到的C语言知识,还让我认识到了编写一个完整的程序不仅要有必备的根底知识,还要耐心,细心,遇到问题不能轻言放弃,灵感可能就会出现在下一秒。 课程设计是把我们所学的理论知识进展系统的总结并应用于实践的良好时机,有利于加强我们用知识理论来分析实际问题的能力,进而加强了我们对知识认识的实践度,稳固了我们的理论知识,深化了对知识的认识,并为走向社会打下一个良好的根底。在这次课程设计中我遇到许多问题和麻烦,得到了教师的帮助和指导,才能够使得这次课程设计顺利的进展下去,另外,在程序调试过程中,也得到很多同学的帮助,给我及时指出错误,提出许多珍贵意见。在此对教师
16、和同学们表示感谢!6 源程序清单#include#include#include#define N sizeof(struct stud)/*先用构造体定义学生信息*/struct stud int num; char name10; char sex8; int age; char major18; int grade; int classes; int building; int floor; int dormitary; struct stud *next; /*next是指向本构造体的类型的指针类型*/;struct stud *h,*p; /*定义指向构造体的指针变量*/FILE *
17、fp; /*定义文件指针*/*建立和输出链表*/struct stud *creat(void) struct stud *p1,*p2,*head; int i,k; printf(Please input the total number of students:n); scanf(%d,&k); head=NULL; printf(Please input the message of the student:nn); if(k0) head=p2=p1=(struct stud*)malloc(N); /*为head,p2,p1申请存储空间,并都指向首结点*/ for(i=1;inum
18、); printf(Input the name:n); scanf(%s,p1-name); printf(Input the sex(man or female):n); scanf(%s,p1-sex); printf(Input the age:n); scanf(%d,&p1-age); printf(Input the major:n); scanf(%s,p1-major); printf(Please input the grade and class:n); scanf(%d%d,&p1-grade,&p1-classes); printf(Please input the
19、building floor and dormitary:n); scanf(%d%d%d,&p1-building,&p1-floor,&p1-dormitary); p2-next=p1; /*将新结点连到表尾*/ p2=p1; /*p2指向新的表尾*/ p2-next=NULL; head=head-next; save_message(head); /*将输入的数据存入文件*/ return head;/*输入模块*/input_message() char v; system(cls); h=creat(); fflush(stdin); printf(nnnn press any
20、key to the main meue!n); v=getchar(); return;/*读取信息*/read_message() struct stud *p1,*p2; h=p1=(struct stud*)malloc(N); /*为了p1申请存储空间,并指向首结点*/ if(fp=fopen(gx1.txt,rb)=NULL) printf(nnn There is no data for the monent!n); return; if(fread(p1,N,1,fp)!=1) return; /*先向p1读入一个数据,假设不能读,返回*/ while(1) p2=(struc
21、t stud*)malloc(N); /*为了p2申请存储空间*/ if(fread(p2,N,1,fp)!=1) break; p1-next=p2; p1=p2; fclose(fp); return;/*输出模块*/output_message(struct stud *p) char v;p=h; system(cls); if(p=NULL) printf(nnnnn There is no datas right now!n); printf(number name sex age major grade class building floor dormitarynn); whi
22、le(p!=NULL) printf(%6d%7s%7s%6d%8s%8d%8d%10d%7d%11dn,p-num,p-name,p-sex,p-age,p-major,p-grade,p-classes,p-building,p-floor,p-dormitary); p=p-next; fflush(stdin); printf(nnnn press any key to the main meue!n); v=getchar(); return;/*删除学生信息*/del_message(struct stud *h) int num; struct stud *p,*p0; syst
23、em(cls); if(h=NULL) return 0; printf(nn Please input the number who you what to delete?n); scanf(%d,&num); p0=h; if(p0-num=num) h=p0-next; free(p0); /*假设首结点是所要删除的数据,那么释放首结点*/ return 1; p=p0-next; while(p!=NULL) if(p-num=num) p0-next=p-next; free(p); return 1; p0=p; p=p-next; return 0;/*修改学生信息*/revis
24、e_message() int num1,choice; struct stud *p0; system(cls); printf(nn Please input the number who you what to revise:n); scanf(%d,&num1); system(cls); p0=h; /*将头结点赋给p0*/ do if(p0-num=num1) printf(n Which you what to revise?n); printf(n 1.numbern); printf(n 2.namen); printf(n 3.sexn); printf(n 4.agen)
25、; printf(n 5.majorn); printf(n 6.graden); printf(n 7.classn); printf(n 8.buildingn); printf(n 9.floorn); printf(n 10.dormiatryn); scanf(%d,&choice); switch(choice) case 1:printf(n Input the new number:n); scanf(%d,&p0-num);break; case 2:printf(n Input the new name:n); scanf(%s,p0-name);break; case 3
26、:printf(n Input the new sex:n); scanf(%s,p0-sex);break; case 4:printf(n Input the new age:n); scanf(%d,&p0-age);break; case 5:printf(n Input the new major:n); scanf(%s,p0-major);break; case 6:printf(n Input the new grade:n); scanf(%d,&p0-grade);break; case 7:printf(n Input the new class:n); scanf(%d
27、,&p0-classes);break; case 8:printf(n Input the new building:n); scanf(%d,&p0-building);break; case 9:printf(n Input the new floor:n); scanf(%d,&p0-floor);break; case 10:printf(n Input the new dormitary:n); scanf(%d,&p0-dormitary);break; break; else p0=p0-next; while(p0!=NULL);/*插入学生信息*/insert_messag
28、e(struct stud *h) struct stud *p,*p0; p=(struct stud *)malloc(N); system(cls); printf(Please input the number of the student:n); scanf(%d,&p-num); printf(Input the name:n); scanf(%s,p-name); printf(Input the sex(man or female):n); scanf(%s,p-sex); printf(Input the age:n); scanf(%d,&p-age); printf(In
29、put the major:n); scanf(%s,p-major); printf(Please input the grade and class:n); scanf(%d%d,&p-grade,&p-classes); printf(Please input the building floor and dormitary:n); scanf(%d%d%d,&p-building,&p-floor,&p-dormitary); p-next=NULL; if(h=NULL) h=p; return 1; p0=h; if(p0-num)(p-num) /*按学号顺序插入*/ p-nex
30、t=h; h=p; return 1; while(p0-next)!=NULL&(p0-next-num)num) p0=p0-next; if(p0-next=NULL) p0-next=p; return 1; else if(p0-next-num)=(p-num) free(p); return 0; p-next=p0-next; p0-next=p; return 1;/*更新模块*/renew_message() int choice; do system(cls); printf(nnn Renew messagenn); printf( 1.Delete messagenn
31、); printf( 2.Revise messagenn); printf( 3.Insert messagenn); printf( 0.Return the main menunn); printf( Please choice(0-3):); scanf(%d,&choice); switch(choice) case 1:del_message(h);output_message(h);break; case 2:revise_message();output_message(h);break; case 3:insert_message(h);output_message(h);break; case 0:break; while(choice!=0);/*按XX查询*/inquire_name() char v,name10; struct stud *p0; system(cls); printf(nnn Please input the name who you what to find:nn); scanf(n%s,name); p0=h; while(p0!=NULL) if(strcmp(p0-name,name)=0) /*用比拟函数比拟*/ printf(nn*
限制150内