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主界面11输入学生信息11输出学生信息12更新学生信息12查询学生信息13排序13统计学生信息145 设计总结146 源程序清单151 需求分析 输入正确密码后进入系统,用read_message()函数先读取文件内容,再在do while

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

3、sage())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_floor() d).按宿舍楼排序(sort_building

4、()7.统计模块 a).按学号统计(count_num()b).按楼层统计(count_floor()c).按楼号统计(count_building()8保存信息(save_message()9退 出 2.2 功能模块说明1输入函数:用来录入数据和有关信息。2输出函数:用来输出录入的相关信息。3. 读函数:将文件中的数据读入。4更新模块:对以存信息进行更新.有以下几个选项:(1)删除函数:用来删除已离校的学生信息。(2)修改函数:用来修改改变宿舍的学生信息。(3)插入函数:用来插入新同学的宿舍信息。5查询模块:输入一项信息,可以得到存入的整条信息,具体有以下: (1)按姓名查询:输入学生姓名,

5、可得到整条学生信息。 (2)按学号查询:输入学生学号,可得到整条学生信息。 (3)按宿舍查询:输入宿舍号,可得到所有住在该宿舍号中的学生的所有信息。 (4)按楼层查询:输入楼层数后,可得到所有住在该层的学生信息。 (5)按宿舍楼查询:输入宿舍楼数,可得到所有住在该楼的学生信息。6排序模块:用来对录入的信息进行整理,使其排列有规律性。(1) 按学号排序:把输入的学号从小到大进行排序。(2) 按宿舍排序:把输入的宿舍从小到大进行排序。(3) 按楼层排序:把输入的楼层从小到大进行排序。(4) 按宿舍楼排序:把输入的宿舍楼从小到大进行排序。7统计模块:用来把录入的信息进行统计,使使用者清楚明了。(1)

6、 按宿舍统计:输入要统计的宿舍号,把这个宿舍里的所有成员输出,并显示在这个宿舍里的总人数。(2) 按楼层统计:输入要统计的楼层,把所有住在这个楼层上的学生信息输出,并显示总人数。(3) 按楼号统计:输入要统计的楼号,把所有住在该楼的学生信息输出,并显示总人数。8保存信息:对信息进行保存,使下次打开时还存在。9退出系统。2.3 程序总体框架主函数流程图:开始 N输入密码Y读函数输入choice进入输入模块Choice 1 Y进入输出模块Choice 2N YN 进入更新模块Choice 3 YN进入查询模块Choice 4 YN 进入排序模块Choice 5读函数 Y进入统计模块Choice 6

7、N 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是输出修改后信息结束查询模块流程图: 开始输入choiceInq

8、uire_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_message(h);choice=3? c

9、hoice=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

10、)sort_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;

11、 char 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_m

12、essage()/*更新模块*/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_mes

13、sage()/*排序模块*/count_floor()/*按楼层统计*/count_building()/*按宿舍楼统计*/count_message()/*统计模块*/save_message(struct stud *h)/*保存信息*/4 调试情况 4.1输入密码进入程序 4.2主界面输入学生信息 .1输入一共有多少个学生信息 .2完成一个学生信息登记输出学生信息更新学生信息可如图:(修改王安的性别)查询学生信息可如图:(按宿舍楼查询)排序统计学生信息如图:(按楼层统计) 该程序中可能还存在一些小问题,比如有的时候它会主动清屏,有的时候不会。并且我在编译的过程中发现自己存在好多毛病,有粗

14、心了等,不注意细节,其实自己也知道细节决定成败,以后我会注意。5 设计总结 通过两周的编程,我完成了学生宿舍管理这个小系统。进一步理解并掌握了C 语言中的精华指针和键表。程序可以流畅运行,实现对数据的录入、修改、插入、删除、排序、查询、统计等基本功能。程序开始时从文件中读取数据,结束时对新数据或更新的数据进行保存,以便下次再次调用。 在编程中也不是一帆风顺的,开始时由于对C语言的许多知识点都遗忘了,导致编程过程中相当吃力,经过一两天的适应后,模块基本上编的得心应手。但当我编写读数据这个模块时遇到了一点问题,程序总是读出一些乱码,并不是我先前存入的数据。经过指导老师耐心的指点下,终于解决了这个问

15、题。这次高级语言程序设计,不仅巩固了我所学到的C语言知识,还让我认识到了编写一个完整的程序不仅要有必备的基础知识,还要耐心,细心,遇到问题不能轻言放弃,灵感可能就会出现在下一秒。 课程设计是把我们所学的理论知识进行系统的总结并应用于实践的良好机会,有利于加强我们用知识理论来分析实际问题的能力,进而加强了我们对知识认识的实践度,巩固了我们的理论知识,深化了对知识的认识,并为走向社会打下一个良好的基础。在这次课程设计中我遇到许多问题和麻烦,得到了老师的帮助和指导,才能够使得这次课程设计顺利的进行下去,另外,在程序调试过程中,也得到很多同学的帮助,给我及时指出错误,提出许多宝贵意见。在此对老师和同学

16、们表示感谢!6 源程序清单#include<stdio.h>#include<string.h>#include<stdlib.h>#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是指向本结构体的类型的指针类型

17、*/;struct 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"); i

18、f(k>0) head=p2=p1=(struct stud*)malloc(N); /*为head,p2,p1申请存储空间,并都指向首结点*/ for(i=1;i<=k;i+) p1=(struct stud*)malloc(N); printf("Please input the number of the student:n"); scanf("%d",&p1->num); printf("Input the name:n"); scanf("%s",p1->name); pr

19、intf("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(&qu

20、ot;%d%d",&p1->grade,&p1->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; sa

21、ve_message(head); /*将输入的数据存入文件*/ return head;/*输入模块*/input_message() char v; system("cls"); h=creat(); fflush(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申请存储空间,并指向首结点

22、*/ 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=(struct stud*)malloc(N); /*为了p2申请存储空间*/ if(fread(p2,N,1,fp)!=1) break; p1->next=p2; p1=p2; fclose(fp); ret

23、urn;/*输出模块*/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"); while(p!=NULL) printf("%6d%7s%7s%6d%8s%8d%8d%10d%7d%11dn"

24、;,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;

25、 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-&g

26、t;next; free(p); return 1; p0=p; p=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

27、->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"); printf("n 5.majorn"); printf("n 6.graden"); printf("n 7.classn"); printf("n

28、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("

29、%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)

30、;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",&p0->classes);break; case 8:printf("n Input the new building:n"); scanf("%d",&p0->buil

31、ding);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_message(struct stud

32、 *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")

33、; scanf("%s",p->sex); printf("Input the age: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);

34、 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->next=h; h=p; return 1; while(p0->next)!=NULL&

35、amp;&(p0->next->num)<(p->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 

36、9;Renew messagenn"); 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_m

37、essage(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);/*按姓名查询*/inquire_name() char v,name10; struct stud *p0; system("cls"); printf("nnn Please input the name who you what to

38、 find:nn"); scanf("n%s",name); p0=h; while(p0!=NULL) if(strcmp(p0->name,name)=0) /*用比较函数比较*/ printf("nn*Inquire by name*nn"); printf("number name sex age major grade class building floor dormitarynn"); printf("%6d%7s%7s%6d%8s%8d%8d%10d%7d%11dn",p0->

39、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_num() char v;int num2; struct stud *p0; system

40、("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"); p

41、rintf("%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;/*按宿舍

42、号查询*/inquire_dormitary() char v;int dormitary2; struct stud *p0; 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

43、"); 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; ff

44、lush(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 what you want to find:nn"); scanf("%d",&floor2); p0=h; while(p0

45、!=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->

温馨提示

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

评论

0/150

提交评论