C语言课程设计学生宿舍管理系统_第1页
C语言课程设计学生宿舍管理系统_第2页
C语言课程设计学生宿舍管理系统_第3页
C语言课程设计学生宿舍管理系统_第4页
C语言课程设计学生宿舍管理系统_第5页
已阅读5页,还剩28页未读 继续免费阅读

下载本文档

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

文档简介

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 源程序清单151 需求分析 输入正确密码后进入系统,用read

2、_message()函数先读取文件内容,再在do while循环中用switch语句进行选择(选一进入输入模块;选二进入输出模块;选三进入更新模块,在更新模块中又包含了三个小的模块:删除,修改,插入;选四进入查询模块,在查询模块中可以根据信息中的学号,姓名,宿舍,楼层,楼号来进行查询;选五进入排序模块,在排序模块中可以根据学号,宿舍,楼层,楼号进行排序;选六进入统计模块,可以根据宿舍,楼层,楼号进行统计。)退出程序时,对信息进行保存,以便下次调用。2 系统总框图和功能模块说明2.1 系统总框图1输入函数(input_message())2输出函数(output_message())3.读函数(

3、read_message())a).删除函数(del_message())4.更新模块 b).修改函数(revise_message()) c)插入函数(insert_message())a).按姓名查询(inquire_name())主函数5.查询模块 b).按学号查询(inquire_num())c).按宿舍查询(inquire_dormitary()d).按楼层查询(inquire_floor()e).按宿舍楼查询(inquire_building() 6.排序模块 a).按学号排序(sort_num() b).按宿舍排序(sort_dormitary() c).按楼层排序(sort_f

4、loor() d).按宿舍楼排序(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)按姓名查询:输入学生姓名,可得到整条学生信息。 (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 进入排

7、序模块choice 5读函数 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

9、)insert_message(h);choice=3? choice=0? 是 结束删除模块流程图:开始输入nump0=hp=p0-nextp-num=nump0-next=p-next;free(p); 是 否p0=p;p=p-next; p=p-next;结束 否按姓名查询流程图: 开始输入name p0=h strcmp(p0-name,name)?=0 是输出p0 否 p0=p0-next 结束 (按学号、宿舍号、楼层、宿舍楼的流程图类似于按姓名查询的流程图)排序模块流程图: 开始输入choiceoutput (h)sort_num()choice=1? 是 否output (h)s

10、ort_dormitary()choice=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; c

11、har major18; int grade; 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_mes

12、sage()/*更新模块*/inquire_name()/*按姓名查询*/inquire_num()/*按学号查询*/inquire_dormitary()/*按宿舍号查询*/inquire_floor()/*按楼层查询*/inquire_building()/*按宿舍楼查询*/inquire_message()/*查询模块*/sort_num()/*按学号排序*/sort_dormitary()/*按宿舍排序*/sort_floor()/*按楼层排序*/sort_building()/*按宿舍楼排序*/output(struct stud *p)/*用于输出排序的模块*/sort_messa

13、ge()/*排序模块*/count_floor()/*按楼层统计*/count_building()/*按宿舍楼统计*/count_message()/*统计模块*/save_message(struct stud *h)/*保存信息*/4 调试情况 4.1输入密码进入程序 4.2主界面4.2.1输入学生信息 输入一共有多少个学生信息 完成一个学生信息登记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

17、 stud *h,*p; /*定义指向结构体的指针变量*/file *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

18、,p2,p1申请存储空间,并都指向首结点*/ for(i=1;inum); 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

19、-classes); printf(please input the 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(); ff

20、lush(stdin); printf(nnnn press any 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读

21、入一个数据,若不能读,返回*/ while(1) p2=(struct 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 clas

22、s building floor dormitarynn); while(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)

23、 int num; struct stud *p,*p0; system(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=

24、p-next; return 0;/*修改学生信息*/revise_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); pr

25、intf(n 3.sexn); printf(n 4.agen); 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);

26、 scanf(%s,p0-name);break; case 3: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

27、input the new class:n); scanf(%d,&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(p

28、0!=null);/*插入学生信息*/insert_message(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

29、:n); scanf(%d,&p-age); printf(input 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(

30、p0-num)(p-num) /*按学号顺序插入*/ p-next=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 messag

31、enn); printf( 1.delete messagenn); 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:inser

32、t_message(h);output_message(h);break; case 0:break; while(choice!=0);/*按姓名查询*/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*inquire by name

33、*nn); printf(number name sex age major grade class building floor dormitarynn); printf(%6d%7s%7s%6d%8s%8d%8d%10d%7d%11dn,p0-num,p0-name,p0-sex,p0-age,p0-major,p0-grade,p0-classes,p0-building,p0-floor,p0-dormitary); p0=p0-next; fflush(stdin); printf(nnnn press any key to the main meue!n); v=getchar()

34、; return;/*按学号查询*/inquire_num() char v;int num2; struct stud *p0; system(cls); printf(nnn please input the number who you what to find:nn); scanf(n%d,&num2); p0=h; while(p0!=null) if(p0-num=num2) printf(nn*inquire by number*nn); printf(number name sex age major grade class building floor dormitarynn

35、); printf(%6d%7s%7s%6d%8s%8d%8d%10d%7d%11dn,p0-num,p0-name,p0-sex,p0-age,p0-major,p0-grade,p0-classes,p0-building,p0-floor,p0-dormitary); p0=p0-next; fflush(stdin); printf(nnnn press any key to the main meue!n);v=getchar(); return;/*按宿舍号查询*/inquire_dormitary() char v;int dormitary2; struct stud *p0;

36、 system(cls); printf(nnn please input the dormitary what you want to find:nn); scanf(n%d,&dormitary2); p0=h; while(p0!=null) if(p0-dormitary=dormitary2) printf(nn*inquire by dormitary*nn); printf(number name sex age major grade class building floor dormitarynn); printf(%6d%7s%7s%6d%8s%8d%8d%10d%7d%1

37、1dn,p0-num,p0-name,p0-sex,p0-age,p0-major,p0-grade,p0-classes,p0-building,p0-floor,p0-dormitary); p0=p0-next; fflush(stdin); printf(nnnn press any key to the main meue!n); v=getchar(); return;/*按楼层查询*/inquire_floor() char v;int floor2; struct stud *p0; system(cls); printf(nnn please input the floor

38、what you want to find:nn); scanf(%d,&floor2); p0=h; while(p0!=null) if(p0-floor=floor2) printf(nn*inquire by floor*nn); printf(number name sex age major grade class building floor dormitarynn); printf(%6d%7s%7s%6d%8s%8d%8d%10d%7d%11dn,p0-num,p0-name,p0-sex,p0-age,p0-major,p0-grade,p0-classes,p0-building,p0-floor,p0-dormitary); p0=p0-next; fflush(stdin);

温馨提示

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

评论

0/150

提交评论