




已阅读5页,还剩16页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
c语言课程设计报告 题目: 学 院 专 业 年级班别 学 号 学生姓名 指导教师 成 绩 2009年12月 1. 课程设计题目,内容,要求设计一个学生通讯录管理系统,在动态链表程序的基础上,设计要求如下(必须使用结构体和链表等数据结构)1建立文件 存储文件使用指定文件名或默认文件名; 可以不保存输入记录,但需要确认是否保存输入记录 如果已有文件,只能在其后追加; 新增记录可以不存入原文件中,以可以用原来的文件覆盖内存的内容;可以将多个个文件记录合并到一个文件中;2文件的存取和显示 可以单独存取文件; 可以随时显示内存中记录的全部内容; 可以直接存取默认文件或指定文件;3删除记录 可以按“姓名”或“电话”方式删除记录并更新内存链表内容; 能给出被删除的信息,输出没有找到的信息; 如果已经是空表,上出时应给出信息并返回主菜单; 如果没有要删除的信息,输出没有找到的信息;删除操作仅限于内存,只有执行记录时,才能覆盖原记录;4查询记录 可以按“姓名”或“电话”或“宿舍”方式查询记录 能给出查询记录的信息;如果查询的信息不存在,输出没有找到的信息;5 整体功能 a可以随时检索、删除、或增加新记录,保存或取消新的记录 b使姓名可由16位字符和数字的混合编码组成 c使电话号码可由18位字符和数字组成d将输出信息加上输出信息信息栏,例如 姓名 电话 性别 年龄 生日 宿舍 李四 1234 男 21 7月1日 东二333 e使用菜单实现功能的正确的选择 f 所有节点信息都是动态生成。6测试程序 应列出测试大纲对程序进行测试; 应保证测试用例测试到程序的各种边缘情况二总体设计系统包括的函数有main.c:整个系统的主函数menu.c:系统的主界面creat.c:创建链表add.c:追加记录del.c:删除记录modify.c:修改记录read.c:从外部文件读取记录save.c:保存记录到外部文件search.c:查找记录skim.c:浏览记录headyy.h:头文件系统功能模块结构图:mainmenucreat.c add.c del.c modify.c read.c save.c search.c skim.c三详细设计 程序清单:-headyy.h-#ifndef null #define null 0 #endif #include#include#include#include#include#define len sizeof(struct addbok)#define pr printf(%-12s%-12s%-12s%-10s%-10s%-10s%-12sn,num.,name,tel.,sex,age,birtday,dormitory);struct addbok /*声明结构体类型*/ long num; char nam16; /*储存编号*/ char tel18; /*储存电话*/ char sex4; /*学生性别*/ int age; /*学生年龄*/ char bir10; /*学生生日*/ char dor13; /*学生宿舍*/ struct addbok * next; ;void print(struct addbok *);具体实现:创建了结构体变量addbok-main.c-#include extern int n=0;void main() int c,color,i=0; struct addbok *head; head=null; for(color=0;color6;color+) textcolor(color); /*字体颜色*/ textbackground(color+2); /*屏幕颜色*/ clrscr(); printf(nnnnnnnnnntttwelcome to students address system); printf(nn); printf(ttttttdesign by yangying); sleep(1); /*延时1秒*/ clrscr(); while(i=0) system(cls); printf(=students address system=); printf(* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *n); printf(* no.:3207006371 name:yangying class:science of computer class1 *n); printf(* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *n); printf(=); c=meun(); switch(c) case 1:head=creat();break; /*指向creat.c*/ case 2:head=add(head);break; /*指向add.c*/ case 3:skim(head);break; /*指向skim.c*/ case 4:head=modify(head);break; /*指向modify.c*/ case 5:search(head);break; /*指向search.c*/ case 6:head=del(head);break; /*指向del.c*/ case 7:head=read();break; /*指向read.c*/ case 8:save(head);break; /*指向save.c*/ case 0: exit(0); /*退出系统*/ default: printf(discorrect!please enter again.nn); getch(); 具体实现:设置了开始的欢迎词,并且对照参考书设置了背景色和字体颜色,每种颜色延时1秒,在此函数中输入了自己的学号班级姓名,并且用switch语句实验了选择功能操作的函数指向。-menu.c-#include extern int n;int meun(void) int i; printf(nn); printf( #menu#n); printf( *n); printf( | 1:creat 2:add item 3:skim items |n); printf( | 4:modify item 5:search item 6:delete item |n); printf( | 7:read file 8:save item 0:exit system |n); printf( *n); printf(nt please choose the number which you want:); scanf(%d,&i); return(i);具体实现:主要表现了主函数的菜单,供用户选择。1选项是建立链表并且创建多个新记录2选项是在链表后面追加若干个记录3选项是浏览存储的记录4选项是修改已有的记录5选项是查找记录6选项是删除系统中的记录7选项是从外部文件读取记录8选项是保存记录到外部文件0选项是推出系统-creat.c-#include extern int n;struct addbok *creat(void) /*引用结构体addbok*/ int i=2; struct addbok *p1,*p2,*head; float a; p1=p2=(struct addbok *)malloc(len); head=null; system(cls); printf(n=enter a new record,stop by0=); printf(n); printf(no.1: n); printf(num.:); scanf(%ld,&p1-num); if(p1-num=0) printf(nn); printf(n-written over-n); getch(); system(cls); return(head); printf(name:); scanf(%s,p1-nam); printf(tel.:); scanf(%s,p1-tel); printf(sex:); scanf(%s,p1-sex); printf(age:); scanf(%d,&p1-age); printf(birthday:); scanf(%s,p1-bir); printf(dormitory:); scanf(%s,p1-dor); while(p1-num!=0) n=n+1; if(n=1) head=p1; else p2-next=p1; p2=p1; p1=(struct addbok *)malloc(len); printf(n); printf(no.%d: n,i); i=i+1; printf(num.:); scanf(%ld,&p1-num); if(p1-num=0) p2-next=null; printf(nn); printf(n-written over-n); getch(); system(cls); return(head); printf(name:); scanf(%s,p1-nam); printf(tel.:); scanf(%s,p1-tel); printf(sex:); scanf(%s,p1-sex); printf(age:); scanf(%d,&p1-age); printf(birthday:); scanf(%s,p1-bir); printf(dormitory:); scanf(%s,p1-dor); p2-next=null; printf(nn); printf(n-written over-n); getch(); system(cls); return(head);具体实现:创建链表并且输入若干个记录,返回菜单使用“0”。-add.c-#include extern int n;struct addbok *add(struct addbok *head) struct addbok *p1,*p2,*p0; float a; int yy=1; system(cls); printf(nthe records you entered will be add to the last record.n);while(yy!=0) p1=(struct addbok *)malloc(len); p0=p2=head; printf( =enter a new record=n); printf(n); printf(num.:); scanf(%ld,p1-num); printf(name:); scanf(%s,p1-nam); printf(tel.:); scanf(%s,p1-tel); printf(sex:); scanf(%s,p1-sex); printf(age:); scanf(%d,&p1-age); printf(birthday:); scanf(%s,p1-bir); printf(dormitory:); scanf(%s,p1-dor); if(p2=null) n=n+1; head=p1; p1=null; else if (p2-next=null) n=n+1; p2-next=p1; p1-next=null; else while(p2-next!=null) p0=p2; p2=p2-next; n=n+1; p2-next=p1; p1-next=null; printf(n -written over-n); printf(nenter0to the menu,any key go on: ); scanf(%d,&yy);system(cls); return(head);具体实现:追加记录,具体操作方法和creat.c一样-del.c-#include extern int n;struct addbok *del(struct addbok *head) struct addbok *p1,*p2; long num; int yy=1; system(cls); printf(n=delete record=n); while(yy!=0) if(head=null) printf(n-empty-n); goto end; printf(nenter the num. you want to delete:); scanf(%ld,&num); p1=head; while (num!=p1-num&p1-next!=null) p2=p1;p1=p1-next; if(num=p1-num) if(p1=head) head=p1-next;n=n-1;printf(n-delete-n);goto end; else p2-next=p1-next;n=n-1;printf(n-delete-n);goto end; else printf(nsorry,can not find the record!n);goto end;end:printf(nenter0to the menu,any number go on: );scanf(%d,&yy); system(cls); return(head);具体实现:删除记录。在没有记录的时候系统将会给出提示“空”,若有记录则按照记录的学生编号删除,若没有用户输入的学生则显示找不到该记录。-modify.c-#include extern int n;struct addbok *modify(struct addbok *head) struct addbok *p1,*p2; long num; int x,yy=1; float a; p1=head; system(cls); printf(n=modify a record=n); if(head=null) printf(n =no record now=n); return(head); printf(nplease input the num.:); scanf(%ld,&num); while (num!=p1-num&p1-next!=null) p2=p1;p1=p1-next; if(num=p1-num) printf(nhoho!the record you want is below:n); printf(%-12s%-12s%-12s%-10s%-10s%-10s%-12s,num.,name,tel.,sex,age,birthday,dormitory);printf(%-12ld%-12s%-12s%-10s%-10d%-10s%-12sn,p1-num,p1-nam,p1-tel,p1-sex,p1-age,p1-bir,p1-dor); printf(n=n); while(yy!=0) printf(n*which one do you want to modify?*n);printf( 1:num. 2:name n); printf( 3:tel. 4:age n); printf(n*n); printf(your choose:); scanf(%d,&x); switch(x) case 1: printf(origin num.:%ldn,p1-num); printf(please input a new num.:); scanf(%ld,&num); p1-num=num; printf(n*success!*n); break; case 2: printf(origin namen,p1-nam); printf(nplease input a new name:); scanf(%s,p1-nam); printf(n*success!*n); break; case 3: printf(origin tel.:%s =n,p1-tel); printf(nplease input a new tel.:); scanf(%s,p1-tel); printf(n*success!*n); break; case 4: printf(origin age:%d =n,p1-age); printf(nplease input the new age:); scanf(%d,&p1-age); printf(n*success!*n); break; printf(nenter0to the menu,any number go on: ); scanf(%d,&yy); else printf(nsorry,can not find the record you want!n);getch(); system(cls); return(head);具体实现:用了switch语句实现了按照学生编号,学生姓名,学生电话,学生年龄这4项功能的修改。修改的记录将替换原有的记录。-read.c-#include extern int n;struct addbok *read(void) int i; struct addbok *p1,*p2,*kt; file *fp; system(cls); fp=fopen(addbok.txt,rb); n=getw(fp); p1=p2=(struct addbok *)malloc(len); kt=p1; fread(p1,sizeof(struct addbok),1,fp); for(i=0;inext=p1; p2=p1; fread(p1,sizeof(struct addbok),1,fp); /*读写一个数据块*/ fclose(fp); printf(n=already reading=nn); getch(); return (kt); 具体实现:从外部文件读取addbok.txt,addbok.txt是保存了用户所输入的记录的文件。其中for语句有点顺序的问题,可是我不知道怎么改。-save.c-#include extern int n;void save(struct addbok *head) file *fp; struct addbok *p; int i; char v; char tr18; p=head; clrscr(); printf(*save?*n); printf(* 1:auto save as addbook_yy.txt *n); printf(* 2:cover a txt *n); printf(* 3:rename a txt *n); printf(*n); v=getch(); switch(v) case 1: system(cls); if(fp=fopen(addbok.txt,wb)=null) printf(cannot open the filen); return; putw(n,fp); for(i=0;inext; fclose(fp); printf(n =success!=nn); getch();break; case 2: clrscr(); printf(nnnnttenter the file name:); scanf(%s,&tr); system(cls); if(fp=fopen(tr,wb)=null) printf(cannot open the filen); return; putw(n,fp); for(i=0;inext; fclose(fp); printf(n =success!=nn); getch();break; case 3: clrscr(); printf(nnnnttenter the file name:); scanf(%s,&tr); system(cls); if(fp=fopen(tr,wb)=null) printf(cannot open the filen); return; putw(n,fp); for(i=0;inext; fclose(fp); printf(n =success!=nn); getch();break; 具体实现:保存记录到外部文件addbook_yy.txt。-search.c-#include extern int n;void search(struct addbok *head) int i,k,j=1;char b,tr18; long t; struct addbok *p;loop: p=head; system(cls); if(head=null) printf(n*search record*n); printf(n=no record!=n); getch(); system(cls); return; while(j!=0) printf(n*search record*n); printf(choose waht you want:n); printf(n1:num.n2:namen3:tel.n4:dormitryntt); b=getch(); switch(b) case 1: printf(please input the num.:); scanf(%ld,&t); printf(n); for(i=0,k=0;inum)=t) k=1; break; p=p-next; if(k=0) printf(*sorry,can not find!*n); else printf(n=); pr; printf(%-12ld%-12s%-12s%-10s%-10d%-10s%-12sn,p-num,p-nam,p-tel,p-sex,p-age,p-bir,p-dor); printf(=n); printf(n); printf(nenter0to the menu,any number go on: ); scanf(%d,&j); p=head;break; case 2: printf(please input the name you want:); scanf(%s,&tr); printf(n); for(i=0,k=0;inam,tr) k=1; break; p=p-next; if(k=0) printf(*sorry,can not find!*n); else printf(n=); pr; printf(%-12ld%-12s%-12s%-10s%-10d%-10s%-12sn,p-num,p-nam,p-tel,p-sex,p-age,p-bir,p-dor); printf(=n); printf(n); printf(nenter0to the menu,any number go on: ); scanf(%d,&j); p=head;break; case 3: printf(please input the tel. you want:); scanf(%s,&tr); printf(n); for(i=0,k=0;itel,tr) k=1; break; p=p-next; if(k=0) printf(*sorry,can not find!*n); else printf(n=); pr; printf(%-12ld%-12s%-12s%-10s%-10d%-10s%-12sn,p-num,p-nam,p-tel,p-sex,p-age,p-bir,p-dor); printf(=n); printf(n); printf(nenter0to the menu,any numbe
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 家委会活动管理制度
- 工厂收快递管理制度
- 弱电间卫生管理制度
- 徒步队安全管理制度
- 德国美术馆管理制度
- 快递集散仓管理制度
- 总分包协调管理制度
- 总裁办司机管理制度
- 感染病门诊管理制度
- 成品糖装卸管理制度
- 四川凉山历年中考语文现代文之说明文阅读7篇(含答案)(2003-2023)
- 基本公共卫生服务项目糖尿病患者管理考核反馈表
- 山东省潍坊市2024-2025学年高二地理下学期期末考试试题
- 陕西省咸阳市兴平市重点中学2025届初三生物试题9月摸底考试试题含解析
- 空间直线平面的垂直课件 高三数学一轮复习
- 中国文化概论期末考试试题
- 《保安员礼仪培训》课件
- 实习生合同电子版
- 日本高尔夫产业市场前景及投资研究报告-培训课件外文版2024.6
- 华佗古本五禽戏智慧树知到期末考试答案章节答案2024年安徽中医药大学
- 24春国家开放大学《家畜环境卫生与设施》形考作业2参考答案
评论
0/150
提交评论