课程设计(论文)用C语言设计宿舍管理查询软件_第1页
课程设计(论文)用C语言设计宿舍管理查询软件_第2页
课程设计(论文)用C语言设计宿舍管理查询软件_第3页
课程设计(论文)用C语言设计宿舍管理查询软件_第4页
课程设计(论文)用C语言设计宿舍管理查询软件_第5页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

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

文档简介

1、 用c语言设计宿舍管理查询软件 第页 共2 4页 用c语言设计宿舍管理查询软件 学生姓名: 指导老师: 摘 要 本课程设计主要解决在一个学校学生宿舍中,管理员对于宿舍学生的管理登记查询的程序设计。数据结构是计算机存储、组织数据的方式。数据结构是指相互之间存在一种或多种特定关系的数据元素的集合1。一般认为,一个数据结构是由数据元素依据某种逻辑联系组织起来的。在课程设计中,系统开发平台为windows 2000,程序设计设计语言采用visual c+,数据库采用ms sql 2000,程序运行平台为windows 98/2000/xp。对于查询使用了二分叉查询法。程序通过调试运行,初步实现了设计目

2、标,并且经过适当完善后,将可以应用在现实中解决实际问题。 关键词 程序设计;查询;c;课程设计;数据结构1 引 言1. 课程设计目的数据结构课程设计的目的是,通过设计掌握数据结构课程中学到的基本理论和算法并综合运用于解决实际问题中,它是理论与实践相结合的重要过程。设计要求学会如何对实际问题定义相关数据结构,并采用恰当的设计方法和算法解决问题,同时训练学生进行复杂程序设计的技能和培养良好的程序设计习惯。在程序设计中,可以用两种方法解决问题:一是传统的结构化程序设计方法,二是更先进的面向对象程序设计方法2。2. 设计说明(1)详细设计思想采用模块化编程思想,将程序划分为11个模块,在逐个模块细化编

3、程,最后再将个个模块组装成软件。(2)程序说明1)需要定义一个结构体:typedef struct pnode /结构体定义 用于存放学生信息的节点char name 8; /姓名 char xh16; /学号 char fh30; /房号personnode;用来存储学生的信息。2)create() /初始条件:必须保证原有记录是空时方可建立 操作结果:建立一个新的数据文件3) readfile() / 初始条件:数据文件已经建立 操作结果:获取次文件的信息 4)serch1()按姓名查找serch2()按学号查找serch3()按宿舍号查找初始条件:数据文件中含有纪录操作结果:不支持模糊查

4、询必须查询项和关键字吻合情况下才可查询。调用按不同关键字查询的子函数若存在相应的查询结果则显示在屏幕上,若查找的纪录不存在则提示该纪录不存在,请建立相应的数据纪5)insert() /添加数据纪录的函数初始条件:必须已经建立了数据文件操作结果:在数据文件中添加新的纪录若没有建立数据文件则添加失败。6) delete() /删除数据纪录的函数初始条件:必须建立了数据库并且数据文件中含有数据纪录操作结果:删除输入学号的学生的一切相关纪录7)updata() /修改数据纪录的函数初始条件:必须建立了数据库并且数据文件中含有数据纪录操作结果:修改输入的学号相对应的学生的一切信息。如不存在相应的纪录则提

5、示不存在8)output() /输出函数 初始条件:数据文件已经建立 操作结果:起泡法排序 按学号顺序输出记录。(3)各函数之间的关系利用主函数调用其他的各个函数,新建数据文件函数create()是其它各个函数的基础,有了它其它函数才能够使用。查询函数insert1.2.3()添加数据纪录函数insert()删除数据纪录函数delete ()修改数据纪录函数updata ()这些函数都是在同一等级上的函数,是平行关系。查询当前所有纪录的函数output()以学号为关键字查询函数serch1()以姓名为关键字查询函数serch2()以床号为关键字查询函数serch3()以宿舍号)这些函数都是查询

6、函数中的子函数,他们之间是平行的关系。3. 算法说明输入学生数据,通过#判断是否输入结束。将数据保存在文件里。查询是否存在文件,存在则输出所查询的学生相关数据,若不存在该学生的数据则输出查询失败。输入学生数据是否输入完毕 存在# ?继续输入学生数据跳出函数ny输入所查学生信息文件中是否存在该学生信息输出该学生信息并跳回主函数输出该学生不存在跳回主函数yn流程图 3-14. 主要变量char name8; 定义学生姓名。char xh16; 定义学号。char fh30; 定义房号床号。注:其他变量程序中均有注释。5. 主要函数功能表5-1 程序中的函数函数功能main();主函数create(

7、);新建数据文件serch1();查询函数serch2();查询函数serch3();查询函数insert();加数据纪录函数delete();删除数据纪录函数updata();修改数据纪录函数readfile();数据文件读取函数output();查询当前所有纪录冰按学号升序输出的函数6. 调试说明程序开始运行时提示用户按照需要选择功能图6-1 提示用户按照格式选择要用的功能对于用户输入的数据,若不在范围内则跳回主菜单。建立文件。读取旧文件。按姓名查询按学号查询插入操作。排序输出。删除操作。当操作完成后每次都会自动跳回主菜单选择9即可退出程序。6 心得体会对我们这一学期实际学到的内容的检验,

8、在课程设计的同时不仅巩固了以前所学过的知识,而且学到了很多在书本上所没有学到过的知识。通过这次课程设计使我懂得了理论与实际相结合是很重要的,只有理论知识是远远不够的,只有把所学的理论知识与实践相结合起来,从理论中得出结论,才能真正的掌握,从而提高自己的实际动手能力和独立思考的能力。要学好数据结构这门课程,不仅要认真的阅读课本知识,更重要的是要通过上机实践才能增强和巩固对课本知识的理解。首先通过实践我发现了自己许多的不足,尤其是露出了对c语言知识基础的掌握不好,许多简单的东西都不知道。在课本上看到各种算法感觉很简单,但是真正的让自己去写一个算法感觉很困难。即使是课本上的原程序算法,自己写起来都感

9、觉有点生疏。在调试过程中经常出现的错误也不是很熟悉。通过实践,使我在这几个方面的认识有所提高。通过实践的学习,我认到学好计算机要重视实践操作,不仅仅是学习数据结构,还是其它的课程,以及其它的计算机方面的知识都要重在实践,所以后在学习过程中,我会更加注视实践操作,使自己更好地学好计算机。回顾起此次数据结构课程设计,至今我仍感慨颇多,的确,从选题到定稿,从理论到实践,遇到了许多问题,也学到了许多东西。虽然程序中不是很完美,但是对于我来说已经不错了,今后还需继续努力。参考文献1严蔚敏,吴伟民. 数据结构(c语言版). 清华大学出版社,20102李文军,李师贤,周晓聪. c+作为计算机专业程序设计入门

10、语言的实践与探讨. 计算机科学,1999,26(4):80833 王晓东.计算机算法设计与分析.电子工业出版社,2007附录1:源程序清单/程序名称:课程设计.c/程序功能:具有实现对学生数据的插入查询删除功能的宿舍查询软件/程序作者:江龙圣/最后修改日期:2010-6-24#include<stdio.h>#include<stdlib.h>#include<string.h>typedef struct pnode /结构体定义 用于存放学生信息的节点 char name 8; /姓名 char xh16; /学号 char fh30; /房号perso

11、nnode;char filename20; /文件名file *fp; /指向文件的指针void creat() /创建新数据文件的函数 创建一个二进制文件 用于存放学生数据 personnode *person; person=(personnode *)malloc(sizeof(personnode); /为节点分配内存 printf("n please enter the filename:n"); scanf("%s",filename); if(fp=fopen(filename,"w+")=null) printf(&

12、quot;n you have no enter the filename,can not font the file"); exit(0); printf("n please enter the name,studentnumbeer (the same length) and roomnumber,spare with space,endwith #n"); scanf("%s",person->name); while(strcmp(person->name,"#") /该循环用于控制 学生信息的录入 当输

13、入#时 学生信息录入完毕 scanf("%s %s",person->xh,person->fh); fprintf(fp,"%-10s%-20s%-50sn",person->name,person->xh,person->fh); scanf("%s",person->name); fclose(fp);void readfile() /文件读取函数 用于打开已有的二进制数据文件printf("n please enter the fileroad:n"); scanf(&q

14、uot;%s",filename); /此处输入为文件的路径 如c:zhang if(fp=fopen(filename,"r+")=null) printf("n can't open thefile:n"); exit(0); fclose(fp);void output() /输出函数 用于输出文件的全部信息 personnode *person; long offset1,offset2; char name18,name28,name38; char xh116,xh216,xh316; char fh130,fh230,fh

15、330;person=(personnode *)malloc(sizeof(personnode); if(fp=fopen(filename,"r")=null) printf("n can't open the file"); exit(0); while(!feof(fp) /此循环用于 对文件数据中关键字学号进行从小到大冒泡排序 int a,b,c,d; /a为循环结束判定变量 b,c,d用于起泡排序时学号交换的替换 if(fp=fopen(filename,"r+")=null) printf("n ca

16、n't open the file"); exit(0); while(!feof(fp) / 从文件头开始遍历 while(!feof(fp) /对两组数据进行排序 offset1=ftell(fp); /获取文件内部当前指针位置 fscanf(fp,"%s%s%sn",person->name,person->xh,person->fh); strcpy(name1,person->name); strcpy (xh1,person->xh); strcpy(fh1,person->fh); if(feof(fp)

17、break; /文件结束 跳出循环 offset2=ftell(fp); /获取文件内部下一指针位置 fscanf(fp,"%s%s%sn",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) /如果 学号1大于等于学号2

18、 怎交换全部数据 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); /将文件指针移动offset1个字节 strcpy(person->name,name1); strcpy(person->xh,xh1); strcpy(person->fh,

19、fh1); fprintf(fp,"%-10s%-20s%-50sn",person->name,person->xh,person->fh);/排序后写入文件 strcpy(person->name,name2); strcpy(person->xh,xh2); strcpy( person->fh,fh2); fprintf(fp,"%-10s%-20s%-50sn",person->name,person->xh,person->fh);/排序后写入文件 fseek(fp,offset2,see

20、k_set); /将文件位置指针从文件头向前移动offset2个字节 rewind(fp); /指向头文件 while(!feof(fp) /此循环用于判断学号是否有序 offset1=ftell(fp); fscanf(fp,"%s%s%sn",person->name,person->xh,person->fh); strcpy (xh1,person->xh); if(feof(fp) a=1; break; offset2=ftell(fp); fscanf(fp,"%s%s%sn",person->name,per

21、son->xh,person->fh); strcpy(xh2,person->xh); b=strlen(xh1); c=strlen(xh2); d=strcmp(xh1,xh2); if(b=c&&d<=0) a=1; /若a为1 则有序 else a=0; /a为0怎无序 break; fseek(fp,offset2,seek_set); if(a) break; /a为1 说明学号已经有序 跳出循环 rewind(fp); if(a) break; /若a为1,则学号已有序排列,跳出总循环,输出文件 rewind(fp); printf(&q

22、uot;n*n"); printf("%35sn","thefile(thefile hava printf as studentnumber)"); printf("%-10s%-20s%-50sn","name","studentnumber","roomnumber"); while(!feof(fp) /次循环用于输出文件 fscanf(fp,"%s%s%sn",person->name,person->xh,person-&

23、gt;fh); printf("%-10s%-20s%-50sn",person->name,person->xh,person->fh); fclose(fp); printf("*nn");void search1() / 按姓名搜索函数 int k=0; char namekey8; personnode *person; person=(personnode *)malloc(sizeof(personnode); printf("n please enter the namehead you need :"

24、); scanf("%s",namekey); if(fp=fopen(filename,"rb")=null) printf("n can't open thefile"); exit(0); while(!feof(fp) fscanf(fp,"%s %s %sn",person->name,person->xh,person->fh); if(!strcmp(namekey,person->name) /比较是否相同 相同则输出结果 否则输出未找到记录 printf("

25、;nn have serched,the courrent is:"); printf("%-10s%-20s%-50sn",person->name,person->xh,person->fh); k=1; if(!k) printf("nn sorry,there is not the current of thiss people n"); fclose(fp);void search2() /按学号搜索函数 int k=0; char xhkey16; personnode *person; person=(perso

26、nnode *)malloc(sizeof(personnode); printf("n please enter the roomnumber you want to serch:"); scanf("%s",xhkey); if(fp=fopen(filename,"rb")=null) printf("n can't open the file "); exit(0); while(!feof(fp) fscanf(fp,"%s %s %sn",person->name,pe

27、rson->xh,person->fh); if(!strcmp(xhkey,person->xh) /比较是否相同 相同则输出结果 否则输出未找到记录 printf("nn have got it,the current is:"); printf("%-10s%-20s%-50sn",person->name,person->xh,person->fh); k=1; if(!k) printf("nn sorry,there is not the current of thiss people n&quo

28、t;); fclose(fp);void search3() /按房号搜索函数 int k=0; char fhkey30; personnode *person; person=(personnode *)malloc(sizeof(personnode); printf("n please enter the roomnumber you want to serch:"); scanf("%s",fhkey); if(fp=fopen(filename,"rb")=null) printf("n can't op

29、en thefile"); exit(0); while(!feof(fp) fscanf(fp,"%s %s %sn",person->name,person->xh,person->fh); if(!strcmp(fhkey,person->fh) /比较是否相同 相同则输出结果 否则输出未找到记录 printf("nn have got it,the current is:"); printf("%-10s%-20s%-50sn",person->name,person->xh,pe

30、rson->fh); k=1; if(!k) printf("nn sorry,there is not the current of thiss peoplen"); fclose(fp);void append() /插入函数 用于像已有文件插入一条新的学生信息记录 personnode *person; person=(personnode *)malloc(sizeof(personnode); if(fp=fopen(filename,"a")=null) printf("n can't open the file&qu

31、ot;); exit(0); printf("n please enter the name,studentnumber and roomnumber n"); scanf("%s %s %s",person->name,person->xh,person->fh); fprintf(fp,"%-10s%-20s%-50sn",person->name,person->xh,person->fh); fclose(fp);void modify() /更新函数 用于修改指定学生姓名的记录 int k

32、=0; long offset; char namekey8; personnode *person; person=(personnode *)malloc(sizeof(personnode); printf("n please enter the studentname you want to updata :"); scanf("%s",namekey); if(fp=fopen(filename,"r+")=null) printf("n can't open thefile"); exit(0)

33、; while(!feof(fp) offset=ftell(fp); fscanf(fp,"%s %s %sn",person->name,person->xh,person->fh); if(!strcmp(namekey,person->name) /比较是否相同 如 k=1; break; if(k) /相同 输出记录并进行修改 printf("n hava got it,the current is:"); printf("%-10s%-20s%-50sn",person->name,perso

34、n->xh,person->fh); printf("n please enter the new studentname,studentnumber and roomnumber :"); scanf("%s %s %s",person->name,person->xh,person->fh); fseek(fp,offset,seek_set); fprintf(fp,"%-10s%-20s%-50sn",person->name,person->xh,person->fh); el

35、se printf("n sorry,there is not the current of this people n"); fclose(fp);void deleted() /删除函数 用于删除指定学生姓名的记录 int k=0; char m; long offset; char namekey8; personnode *person; person=(personnode *)malloc(sizeof(personnode); printf("n please enter the name you want to delete :"); s

36、canf("%s",namekey); if(fp=fopen(filename,"r+")=null) printf("n can't open the file "); exit(0); while(!feof(fp) /此循环遍历整个文件 查找需要删除的记录 offset=ftell(fp); fscanf(fp,"%s%s%sn",person->name,person->xh,person->fh); if(!strcmp(namekey,person->name) k=1; break; if(k) printf("n hava got it,the current is:"); printf("%-10s%-20s%-50sn",person->name,person->xh,person

温馨提示

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

评论

0/150

提交评论