1课程设计 题目十.docx

上传人:b****6 文档编号:3305326 上传时间:2022-11-21 格式:DOCX 页数:16 大小:48.20KB
下载 相关 举报
1课程设计 题目十.docx_第1页
第1页 / 共16页
1课程设计 题目十.docx_第2页
第2页 / 共16页
1课程设计 题目十.docx_第3页
第3页 / 共16页
1课程设计 题目十.docx_第4页
第4页 / 共16页
1课程设计 题目十.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

1课程设计 题目十.docx

《1课程设计 题目十.docx》由会员分享,可在线阅读,更多相关《1课程设计 题目十.docx(16页珍藏版)》请在冰豆网上搜索。

1课程设计 题目十.docx

1课程设计题目十

 

学生宿舍管理系统

一设计内容及要求:

为宿舍管理人员编写一个宿舍管理查询软件。

要求:

1)建立数据文件,数据文件按关键字(姓名,学号,房号)进行排序(冒泡,选择,插入排序等任意一种)

2)查询菜单(用二分法实现以下操作)

A.按姓名查询

B.按学号查询

C.按房号查询

二概要设计

1)需要定义一个结构体:

typedefstructpnode/*结构体定义用于存放学生信息的节点*/

用来存储学生的信息。

2)create()

 /*初始条件:

必须保证原有记录是空时方可建立*/

操作结果:

建立一个新的数据文件

3)readfile()

/*初始条件:

数据文件已经建立*/

操作结果:

获取次文件的信息

4)serch1()按姓名查找

serch2()按学号查找

serch3()按宿舍号查找

初始条件:

数据文件中含有纪录

操作结果:

不支持模糊查询必须查询项和关键字吻合情况下才可查询。

调用按不同关键字查询的子函数

若存在相应的查询结果则显示在屏幕上,若查找的纪录不存在则提示该纪录不存在,请建立相应的数据纪

5)insert()

/*添加数据纪录的函数*/

初始条件:

必须已经建立了数据文件

操作结果:

在数据文件中添加新的纪录

若没有建立数据文件则添加失败。

6)delete()

/*删除数据纪录的函数*/

初始条件:

必须建立了数据库并且数据文件中含有数据纪录

操作结果:

删除输入学号的学生的一切相关纪录

7)updata()

/*修改数据纪录的函数*/

初始条件:

必须建立了数据库并且数据文件中含有数据纪录

操作结果:

修改输入的学号相对应的学生的一切信息。

如不存在相应的纪录则提示不存在

8)output()

/*输出函数*/

初始条件:

数据文件已经建立

操作结果:

起泡法排序按学号顺序输出记录

2>本程序包含10个函数:

1.主函数main()

2.新建数据文件create()

3.查询函数serch1()

4.查询函数serch2()

5.查询函数serch3()

6.加数据纪录函数insert()

7.删除数据纪录函数delete()

8.修改数据纪录函数updata()

9.数据文件读取函数readfile()

10.查询当前所有纪录冰按学号升序输出的函数output()

三设计思想:

采用模块化编程思想,将程序划分为11个模块,在逐个模块细化编程,最后再将个个模块组装成软件。

四测试

测试结果及数据如下:

五程序源代码如下:

#include

#include

#include

typedefstructpnode

{

charname[8];

charxh[16];

charfh[30];

}personnode;

charfilename[20];

FILE*fp;

voidcreat()

{

personnode*person;

person=(personnode*)malloc(sizeof(personnode));

printf("\n请输入thefilename:

\n");

scanf("%s",filename);

if((fp=fopen(filename,"w+"))==NULL)

{

printf("\n你还没有输入,不能建立档案");

exit(0);

}

printf("\n请输入姓名,学号(thesamelength),寝室号,剩余空间,endwith#\n");

scanf("%s",person->name);

while(strcmp(person->name,"#"))

{

scanf("%s%s",person->xh,person->fh);

fprintf(fp,"%-10s%-20s%-50s\n",person->name,person->xh,person->fh);

scanf("%s",person->name);

}

fclose(fp);

}

voidreadfile()

{printf("\npleaseenterthefileroad:

\n");

scanf("%s",filename);

if((fp=fopen(filename,"r+"))==NULL)

{

printf("\ncan'topenthefile:

\n");

exit(0);

}

fclose(fp);

}

voidoutput()

{

personnode*person;

longoffset1,offset2;

charname1[8],name2[8],name3[8];

charxh1[16],xh2[16],xh3[16];

charfh1[30],fh2[30],fh3[30];

person=(personnode*)malloc(sizeof(personnode));

if((fp=fopen(filename,"r"))==NULL)

{

printf("\ncan'topenthefile");

exit(0);

}

while(!

feof(fp))

{

inta,b,c,d;

if((fp=fopen(filename,"r+"))==NULL)

{

printf("\ncan'topenthefile");

exit(0);

}

while(!

feof(fp))

{

while(!

feof(fp))

{

offset1=ftell(fp);

fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);

strcpy(name1,person->name);

strcpy(xh1,person->xh);

strcpy(fh1,person->fh);

if(feof(fp))break;

offset2=ftell(fp);

fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);

strcpy(name2,person->name);

strcpy(xh2,person->xh);

strcpy(fh2,person->fh);

b=strlen(xh1);

c=strlen(xh2);

d=strcmp(xh1,xh2);

if(b==c&&d>0)

{

strcpy(name3,name1);

strcpy(name1,name2);

strcpy(name2,name3);

strcpy(xh3,xh1);

strcpy(xh1,xh2);

strcpy(xh2,xh3);

strcpy(fh3,fh1);

strcpy(fh1,fh2);

strcpy(fh2,fh3);

fseek(fp,offset1,SEEK_SET);

strcpy(person->name,name1);

strcpy(person->xh,xh1);

strcpy(person->fh,fh1);

fprintf(fp,"%-10s%-20s%-50s\n",person->name,person->xh,person->fh);

strcpy(person->name,name2);

strcpy(person->xh,xh2);

strcpy(person->fh,fh2);

fprintf(fp,"%-10s%-20s%-50s\n",person->name,person->xh,person->fh);

}

fseek(fp,offset2,SEEK_SET);

}

rewind(fp);

while(!

feof(fp))

{

offset1=ftell(fp);

fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);

strcpy(xh1,person->xh);

if(feof(fp)){a=1;break;}

offset2=ftell(fp);

fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);

strcpy(xh2,person->xh);

b=strlen(xh1);

c=strlen(xh2);

d=strcmp(xh1,xh2);

if(b==c&&d<=0)a=1;

else{a=0;

break;}

fseek(fp,offset2,SEEK_SET);

}

if(a)break;

rewind(fp);

}

if(a)break;

}

rewind(fp);

printf("\n*************************************************************\n");

printf("%35s\n","thefile(thefilehavaprintfasstudentnumber)");

printf("%-10s%-20s%-50s\n","name","studentnumber","roomnumber");

while(!

feof(fp))

{

fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);

printf("%-10s%-20s%-50s\n",person->name,person->xh,person->fh);

}

fclose(fp);

printf("**************************************************************\n\n");

}

 

voidsearch1()

{

intk=0;

charnamekey[8];

personnode*person;

person=(personnode*)malloc(sizeof(personnode));

printf("\npleaseenterthenameheadyouneed:

");

scanf("%s",namekey);

if((fp=fopen(filename,"rb"))==NULL)

{

printf("\ncan'topenthefile");

exit(0);

}

while(!

feof(fp))

{

fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);

if(!

strcmp(namekey,person->name))

{

printf("\n\nhaveserched,thecourrentis:

");

printf("%-10s%-20s%-50s\n",person->name,person->xh,person->fh);

k=1;

}

}

if(!

k)printf("\n\nsorry,thereisnotthecurrentofthisspeople\n");

fclose(fp);

}

 

voidsearch2()

{

intk=0;

charxhkey[16];

personnode*person;

person=(personnode*)malloc(sizeof(personnode));

printf("\npleaseentertheroomnumberyouwanttoserch:

");

scanf("%s",xhkey);

if((fp=fopen(filename,"rb"))==NULL)

{

printf("\ncan'topenthefile");

exit(0);

}

while(!

feof(fp))

{

fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);

if(!

strcmp(xhkey,person->xh))

{

printf("\n\nhavegotit,thecurrentis:

");

printf("%-10s%-20s%-50s\n",person->name,person->xh,person->fh);

k=1;

}

}

if(!

k)printf("\n\n对不起,目前没有没有这个人\n");

fclose(fp);

}

 

voidsearch3()

{

intk=0;

charfhkey[30];

personnode*person;

person=(personnode*)malloc(sizeof(personnode));

printf("\n请输入你想要查找的寝室号:

");

scanf("%s",fhkey);

if((fp=fopen(filename,"rb"))==NULL)

{

printf("\n不能打开该档案");

exit(0);

}

while(!

feof(fp))

{

fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);

if(!

strcmp(fhkey,person->fh))

{

printf("\n\n有该信息,该信息是:

");

printf("%-10s%-20s%-50s\n",person->name,person->xh,person->fh);

k=1;

}

}

if(!

k)printf("\n\n对不起,这没有该人当前的信息\n");

fclose(fp);

}

voidappend()

{

personnode*person;

person=(personnode*)malloc(sizeof(personnode));

if((fp=fopen(filename,"a"))==NULL)

{

printf("\ncan'topenthefile");

exit(0);

}

printf("\n请输入姓名,学号和寝室号\n");

scanf("%s%s%s",person->name,person->xh,person->fh);

fprintf(fp,"%-10s%-20s%-50s\n",person->name,person->xh,person->fh);

fclose(fp);

}

 

voidmodify()

{

intk=0;

longoffset;

charnamekey[8];

personnode*person;

person=(personnode*)malloc(sizeof(personnode));

printf("\n请输入你想更新的学号:

");

scanf("%s",namekey);

if((fp=fopen(filename,"r+"))==NULL)

{

printf("\n不能打开该档案");

exit(0);

}

while(!

feof(fp))

{

offset=ftell(fp);

fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);

if(!

strcmp(namekey,person->name))

{

k=1;

break;

}

}

if(k)

{

printf("\n有,目前是:

");

printf("%-10s%-20s%-50s\n",person->name,person->xh,person->fh);

printf("\n请输入姓名,学号和寝室号:

");

scanf("%s%s%s",person->name,person->xh,person->fh);

fseek(fp,offset,SEEK_SET);

fprintf(fp,"%-10s%-20s%-50s\n",person->name,person->xh,person->fh);

}

elseprintf("\nsorry,thereisnotthecurrentofthispeople\n");

fclose(fp);

}

 

voiddeleted()

{

intk=0;

charm;

longoffset;

charnamekey[8];

personnode*person;

person=(personnode*)malloc(sizeof(personnode));

printf("\npleaseenterthenameyouwanttodelete:

");

scanf("%s",namekey);

if((fp=fopen(filename,"r+"))==NULL)

{

printf("\n不能打开该档案");

exit(0);

}

while(!

feof(fp))

{

offset=ftell(fp);

fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);

if(!

strcmp(namekey,person->name))

{

k=1;

break;

}

}

if(k)

{

printf("\nhavagotit,thecurrentis:

");

printf("%-10s%-20s%-50s\n",person->name,person->xh,person->fh);

printf("\nareyousuretodeleteit?

y/n?

");

scanf("%s",&m);

if(m=='y')

{

fseek(fp,offset,SEEK_SET);

fprintf(fp,"%-10s%-20s%-50s\n","","","");

}

elserewind(fp);

}

elseprintf("\n对不起,这没有该学生的数据。

\n");

fclose(fp);

}

 

voidmain()

{

intm,flag=1;

while(flag)

{

printf("%33s\n","thefile");

printf("--------------------------------------------------------------------------------\n");

printf("\t\t0-------------创建一个新的数据档案\n");

printf("\t\t1-------------读取以前的数据\n");

printf("\t\t2------------查找姓名\n");

printf("\t\t3------------查找学号\n");

printf("\t\t4------------查找寝室号\n");

printf("\t\t5-------------更新\n");

printf("\t\t6-------------删除\n");

printf("\t\t7-------------修改\n");

printf("\t\t8-------------输出\n");

printf("\t\t9-------------退出\n");

printf("--------------------------------------------------------------------------------\n");

printf("\tpleasechoice(0-----------9)\n");

scanf("%d",&m);

switch(m)

{case0:

creat();break;

case1:

readfile();break;

case2:

search1();break;

case3:

search2();break;

case4:

search3();break;

case5:

modify();break;

case6:

deleted();break;

case7:

append();break;

case8:

output();break;

case9:

exit(0);

}

}

}

六自我评价:

总体上看基本完成了课题任务,但程序的许多细节上差强人意不够好。

比如操作界面不够美观,使用过程中方法繁琐不精练,保密性差等。

运用得较好的是利用主函数调用其他的各个函数,新建数据文件函数create()是其它各个函数的基础,有了它其它函数才能够使用。

查询函数insert1.2.3()添加数据纪录函数insert()删除数据纪录函数delete()修改数据纪录函数updata()这些函数都是在同一等级上的函数,是平行关系。

查询当前所有纪录的函数output()以学号为关键字查询函数serch1()以姓名为关键字查询函数serch2()以床号为关键字查询函数serch3()以宿舍号)这些函数都是查询函数中的子函数,他们之间是平行的关系。

在课程设计的同时不仅巩固了以前所学过的知识,而且学到了很多在书本上所没有学到过的知识。

通过这次课程设计使我懂得了理论与实际相结合是很重要的,只有理论知识是远远不够的,只有把所学的理论知识与实践相结合起来,从理论中得出结论,才能真正的掌握,从而提高自己的实际动手能力和独立思考的能力。

要学好数据结构这门课程,不仅要认真的阅读课本知识,更重要的是要通过上机实践才能增强和巩固对课本知识的理解。

首先通过实践我发现了自己许多的不足,尤其是露出了对C语言知识基础的掌握不好,许多简单的东西都不知道。

在课本上看到各种算法感觉很简单,但是真正的让自己去写一个算法感觉很困难。

即使是课本上的原程序算法,自己写起来都感觉有点生疏。

在调试过程中经常出现的错误也不是很熟悉。

通过实践,使我在这几个方面的认识有所

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

当前位置:首页 > 小学教育 > 语文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1