资源描述
程序设计工程训练汇报
学生宿舍管理系统
课程名称 程序设计工程训练
姓 名
院(系) 信息科学和技术学院
专业班级
学 号
指导老师
教务处制
目 录
1 需求分析 1
2 系统总框图和功效模块说明 2
2.1 系统总框图。 2
2.2 功效模块说明 3
2.3 程序总体框架 4
3 系统设计 10
3.1 关键结构体 10
3.2关键功效函数 10
4 调试情况 11
4.1输入密码进入程序 11
4.2主界面 11
4.2.1输入学生信息 11
4.2.2输出学生信息 12
4.2.3更新学生信息 12
4.2.4查询学生信息 13
4.2.5排序 13
4.2.6统计学生信息 14
5 设计总结 14
6 源程序清单 15
1 需求分析
输入正确密码后进入系统,用read_message()函数先读取文件内容,再在do while循环中用switch语句进行选择(选一进入输入模块;选二进入输出模块;选三进入更新模块,在更新模块中又包含了三个小模块:删除,修改,插入;选四进入查询模块,在查询模块中能够依据信息中学号,姓名,宿舍,楼层,楼号来进行查询;选五进入排序模块,在排序模块中能够依据学号,宿舍,楼层,楼号进行排序;选六进入统计模块,能够依据宿舍,楼层,楼号进行统计。)退出程序时,对信息进行保留,方便下次调用。
2 系统总框图和功效模块说明
2.1 系统总框图
1.输入函数(input_message())
2.输出函数(output_message())
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_floor())
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.查询模块:输入一项信息,能够得到存入整条信息,具体有以下:
(1)按姓名查询:输入学生姓名,可得到整条学生信息。
(2)按学号查询:输入学生学号,可得到整条学生信息。
(3)按宿舍查询:输入宿舍号,可得到全部住在该宿舍号中学生全部信息。
(4)按楼层查询:输入楼层数后,可得到全部住在该层学生信息。
(5)按宿舍楼查询:输入宿舍楼数,可得到全部住在该楼学生信息。
6.排序模块:用来对录入信息进行整理,使其排列有规律性。
(1) 按学号排序:把输入学号从小到大进行排序 。
(2) 按宿舍排序:把输入宿舍从小到大进行排序 。
(3) 按楼层排序:把输入楼层从小到大进行排序 。
(4) 按宿舍楼排序:把输入宿舍楼从小到大进行排序 。
7.统计模块:用来把录入信息进行统计,使使用者清楚明了。
(1) 按宿舍统计:输入要统计宿舍号,把这个宿舍里全部组员输出,并显示在这个宿舍里总人数。
(2) 按楼层统计:输入要统计楼层,把全部住在这个楼层上学生信息输出,并显示总人数。
(3) 按楼号统计:输入要统计楼号,把全部住在该楼学生信息输出,并显示总人数。
8.保留信息:对信息进行保留,使下次打开时还存在。
9.退出系统。
2.3 程序总体框架
主函数步骤图:
开始
N
输入密码
Y
读函数
输入choice
进入输入模块
Choice 1
Y
进入输出模块
Choice 2
N Y
N
进入更新模块
Choice 3
Y
N
进入查询模块
Choice 4
Y
N
进入排序模块
Choice 5
读函数
Y
进入统计模块
Choice 6
N Y
N
退出
Choice 0
Y
保留函数
结束
修改模块步骤图:
开始
输入学号
输入choice
choice=1?
输入修改后num
是
否
输入修改后name
choice=2?
是
否
输入修改后sex
choice=3?
是
否
输入修改后age
choice=4?
是
否
输入修改后major
choice=5?
是
Choice=6?
输入修改后grade
否
是
否
是Choice=7?
输入修改后class
否
是
Choice=8?
输入修改后building
否
输入修改后floor
是Choice=9?
否
Choice=10?
输入修改后dormiatry
是
输出修改后信息
结束
查询模块步骤图:
开始
输入choice
Inquire_name
choice=1?
是
否
Inquire_num
choice=2?
是
否
是
Inquire_dormitary
choice=3?
否
Inquire_floor
choice=4?
是
否
choice=5?
Inquire_building
是
否
choice=0?
是
结束
更新模块步骤图:
开始
输入choice
output_message(h)
del_message(h)
choice=1?
是
否
output_message(h)
revise_message()
choice=2?
是
否
是
output_message(h)
insert_message(h);
choice=3?
choice=0?
是
结束
删除模块步骤图:
开始
输入num
p0=h
p=p0->next
p->num==num
p0->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
结束
(按学号、宿舍号、楼层、宿舍楼步骤图类似于按姓名查询步骤图)
排序模块步骤图:
开始
输入choice
output (h)
sort_num()
choice=1?
是
否
output (h)
sort_dormitary()
choice=2?
是
否
是
choice=3?
sort_floor()
output (h)
否
choice=4?
sort_building()
output (h)
是
否
choice=0?
是
结束
统计模块步骤图:
开始
输入choice
count_dormitary()
choice=1?
是
否
count_floor()
choice=2?
是
否
是
count_building()
choice=3?
choice=0?
是
结束
3 系统设计
3.1 关键结构体
struct stud
{
int num;
char name[10];
char sex[8];
int age;
char major[18];
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_message()/*更新模块*/
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_message()/*排序模块*/
count_floor()/*按楼层统计*/
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统计学生信息
图:(按楼层统计)
该程序中可能还存在部分小问题,比如有时候它会主动清屏,有时候不会。而且我在编译过程中发觉自己存在好多毛病,有粗心了等,不注意细节,其实自己也知道细节决定成败,以后我会注意。
5 设计总结
经过两周编程,我完成了学生宿舍管理这个小系统。深入了解并掌握了C 语言中精华指针和键表。程序能够流畅运行,实现对数据录入、修改、插入、删除、排序、查询、统计等基础功效。程序开始时从文件中读取数据,结束时对新数据或更新数据进行保留,方便下次再次调用。
在编程中也不是一帆风顺,开始时因为对C语言很多知识点全部遗忘了,造成编程过程中相当吃力,经过一两天适应后,模块基础上编得心应手。但当我编写读数据这个模块时碰到了一点问题,程序总是读出部分乱码,并不是我先前存入数据。经过指导老师耐心指点下,最终处理了这个问题。
这次高级语言程序设计,不仅巩固了我所学到C语言知识,还让我认识到了编写一个完整程序不仅要有必备基础知识,还要耐心,细心,碰到问题不能轻言放弃,灵感可能就会出现在下一秒。
课程设计是把我们所学理论知识进行系统总结并应用于实践良好机会,有利于加强我们用知识理论来分析实际问题能力,进而加强了我们对知识认识实践度,巩固了我们理论知识,深化了对知识认识,并为走向社会打下一个良好基础。
在这次课程设计中我碰到很多问题和麻烦,得到了老师帮助和指导,才能够使得这次课程设计顺利进行下去,另外,在程序调试过程中,也得到很多同学帮助,给我立即指犯错误,提出很多宝贵意见。在此对老师和同学们表示感谢!
6 源程序清单
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N sizeof(struct stud)
/*先用结构体定义学生信息*/
struct stud
{
int num;
char name[10];
char sex[8];
int age;
char major[18];
int grade;
int classes;
int building;
int floor;
int dormitary;
struct stud *next; /*next是指向本结构体类型指针类型*/
};
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:\n\n");
if(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);
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 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("\n\n\n\n\ 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("\n\n\n 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);
return;
}
/*输出模块*/
output_message(struct stud *p)
{ char v;
p=h;
system("cls");
if(p==NULL)
printf("\n\n\n\n\n There is no datas right now!\n");
printf("number name sex age major grade class building floor dormitary\n\n");
while(p!=NULL)
{
printf("%6d%7s%7s%6d%8s%8d%8d%10d%7d%11d\n",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("\n\n\n\n\ press any key to the main meue!!!!\n");
v=getchar();
return;
}
/*删除学生信息*/
del_message(struct stud *h)
{ int num;
struct stud *p,*p0;
system("cls");
if(h==NULL) return 0;
printf("\n\n 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;
}
/*修改学生信息*/
revise_message()
{ int num1,choice;
struct stud *p0;
system("cls");
printf("\n\n 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.number\n");
printf("\n 2.name\n");
printf("\n 3.sex\n");
printf("\n 4.age\n");
printf("\n 5.major\n");
printf("\n 6.grade\n");
printf("\n 7.class\n");
printf("\n 8.building\n");
printf("\n 9.floor\n");
printf("\n 10.dormiatry\n");
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: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",&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_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:\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((p0->num)>(p->num)) /*按学号次序插入*/
{ p->next=h;
h=p;
return 1;
}
while((p0->next)!=NULL&&(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("\n\n\n ~~~~~~~~'Renew message~~~~~~~~\n\n");
printf(" 1.Delete message\n\n");
printf(" 2.Revise message\n\n");
printf(" 3.Insert message\n\n");
printf(" 0.Return the main menu\n\n");
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);
}
/*按姓名查询*/
inquire_name()
{ char v,name[10];
struct stud *p0;
system("cls"
展开阅读全文