C语言课程设计报告2.doc

上传人:laozhun 文档编号:2384953 上传时间:2023-02-17 格式:DOC 页数:21 大小:68.50KB
返回 下载 相关 举报
C语言课程设计报告2.doc_第1页
第1页 / 共21页
C语言课程设计报告2.doc_第2页
第2页 / 共21页
C语言课程设计报告2.doc_第3页
第3页 / 共21页
C语言课程设计报告2.doc_第4页
第4页 / 共21页
C语言课程设计报告2.doc_第5页
第5页 / 共21页
点击查看更多>>
资源描述

《C语言课程设计报告2.doc》由会员分享,可在线阅读,更多相关《C语言课程设计报告2.doc(21页珍藏版)》请在三一办公上搜索。

1、C语言课程设计报告 题目: 学 院 专 业 年级班别 学 号 学生姓名 指导教师 成 绩 2009年12月 1. 课程设计题目,内容,要求设计一个学生通讯录管理系统,在动态链表程序的基础上,设计要求如下(必须使用结构体和链表等数据结构)1建立文件 存储文件使用指定文件名或默认文件名; 可以不保存输入记录,但需要确认是否保存输入记录 如果已有文件,只能在其后追加; 新增记录可以不存入原文件中,以可以用原来的文件覆盖内存的内容;可以将多个个文件记录合并到一个文件中;2文件的存取和显示 可以单独存取文件; 可以随时显示内存中记录的全部内容; 可以直接存取默认文件或指定文件;3删除记录 可以按“姓名”

2、或“电话”方式删除记录并更新内存链表内容; 能给出被删除的信息,输出没有找到的信息; 如果已经是空表,上出时应给出信息并返回主菜单; 如果没有要删除的信息,输出没有找到的信息;删除操作仅限于内存,只有执行记录时,才能覆盖原记录;4查询记录 可以按“姓名”或“电话”或“宿舍”方式查询记录 能给出查询记录的信息;如果查询的信息不存在,输出没有找到的信息;5 整体功能 a可以随时检索、删除、或增加新记录,保存或取消新的记录 b使姓名可由16位字符和数字的混合编码组成 c使电话号码可由18位字符和数字组成d将输出信息加上输出信息信息栏,例如 姓名 电话 性别 年龄 生日 宿舍 李四 1234 男 21

3、 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 S

4、earch.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; /*储存编号*/ cha

5、r 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(co

6、lor); /*字体颜色*/ 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(* * * * * * * * * * * * * * * * * * * * * *

7、 * * * * * * * * * * * * * * * * * *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);

8、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: p

9、rintf(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 it

10、em 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选项是保存记录到外

11、部文件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

12、-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

13、!=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(

14、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 ex

15、tern 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(%l

16、d,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-n

17、ext=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

18、 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-

19、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);具体实现:删除记录。在没有记录的时候系统将会给出提示“空”,若有记录则按照记录的学生编号删除,若没有用户输入的学生则显示找不到该记录。

20、-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

21、-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(

22、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

23、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

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

25、 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); print

26、f(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 addb

27、ook_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(); print

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

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

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

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号