C语言版数据结构课程设计文章编辑系统 .doc
课程设计说明书 NO.1文章编辑系统1、课程设计目的(1)较熟练地掌握语言的基本内容及程序设计的基本方法与编程技巧。(2)较熟练地掌握在系统上编辑、编译、连接和运行C程序的方法。(3)通过设计一个完整程序,掌握数据结构的算法编写、类C语言算法转换成C程序并上机调试的基本方法。2、课程设计方案论证2.1 设计思路(1)定义结构体 struct line,文本行采用顺序存储,行与行之间采用链式存储文章编辑系统统计字符删除字符统计文字查找字符图1:功能模块图(2)主要函数:int CountNumber(LINE * &head) /*统计数字数*/ 沈 阳 大 学课程设计说明书 NO.2图2:统计数字函数流程图:开始*p=head,count=0int len=str len(p->data)i=0i<lenp->datai>=48 &&p->datai<=57count+i+p=p->next!p=NULL结束NYNYN 沈 阳 大 学课程设计说明书 NO.3int FindString(LINE * &head,char *str) /*统计str在文章中出现的次数*/开始count=0;h=0;len1=0; len2=strlen(str);p->datai=str0i+k=0;j=0;p->datai+j=strjk+;j+;k=len2count+;i=i+k-1;结束YNYNNY图3:统计str在文章中的出现次数 沈 阳 大 学课程设计说明书 NO.42.2 源程序清单#include <string.h>#include <stdio.h> typedef struct line char *data; struct line *next;LINE; void Create(LINE * &head)LINE *p;printf ("请输入一页文章,以#为结尾(每行最多输入80字符!):n");p=(struct line*)malloc(sizeof(struct line); head=p; char tmp200; for(;1;) gets(tmp); if(strlen(tmp)>80) printf("每行最多输入80字符"); break; if(tmp0=35)break; p=p->next=(struct line*)malloc(sizeof(struct line); p->data=(char*)malloc(strlen(tmp); strcpy(p->data,tmp); if(tmpstrlen(tmp)-1=35) p->datastrlen(tmp)-1='0' 沈 阳 大 学课程设计说明书 NO.5 break; p->next=NULL; head=head->next;int CountLetter(LINE * &head) LINE *p=head; int count=0;do int Len=strlen(p->data); for(int i=0;i<Len;i+)if(p->datai>='a'&&p->datai<='z')|(p->datai>='A'&&p->datai<='Z') count+; while(p=p->next)!=NULL); return count; int CountNumber(LINE * &head) LINE *p=head; int count=0; do int Len=strlen(p->data); for(int i=0;i<Len;i+) if(p->datai>=48 && p->datai<=57)count+; 沈 阳 大 学课程设计说明书 NO.6 while(p=p->next)!=NULL); return count;int CountSpace(LINE * &head) LINE *p=head; int count=0; do int Len=strlen(p->data); for(int i=0;i<Len;i+) if(p->datai=32)count+; while(p=p->next)!=NULL); return count;/*统计文章的总字数*/int CountAll(LINE * &head) LINE *p=head; int count=0; do count+=strlen(p->data); while(p=p->next)!=NULL); return count; 沈 阳 大 学课程设计说明书 NO.7int FindString(LINE * &head,char *str) LINE *p=head; int count=0; int h=0; int len1=0; int len2=strlen(str); int i,j,k; do len1=strlen(p->data); for(i=0;i<len1;i+) if(p->datai=str0)k=0; for(j=0;j<len2;j+) if(p->datai+j=strj) k+;if(k=len2)count+;i=i+k-1; while(p=p->next)!=NULL); return count;void delstringword(char *s,char *str) char *p=strstr(s,str); 沈 阳 大 学课程设计说明书 NO.8char tmp80; int len=strlen(s); int i=len-strlen(p); int j=i+strlen(str); int count=0; for(int m=0;m<i;m+)tmpcount+=sm; for(int n=j;n<len;n+)tmpcount+=sn; tmpcount='0' strcpy(s,tmp); void DelString(LINE * &head,char *str) LINE *p=head; do if(strstr(p->data,str)!=NULL)delstringword(p->data,str);while(p=p->next)!=NULL); void OutPut(LINE * &head) LINE *p=head; do printf("%sn",p->data); while(p=p->next)!=NULL); 沈 阳 大 学课程设计说明书 NO.9void main() int i=0; int operate;LINE * head;Create(head); printf("输入的文章为:n"); OutPut(head); printf("n"); printf("全部字母数:%d n",CountLetter(head); printf("数字个数:%d n",CountNumber(head); printf("空格个数: %d n",CountSpace(head); printf("文章总字数: %d n",CountAll(head); char str120,str220; printf("n"); printf("*n"); printf("* 菜 单 *n"); printf("*n"); printf("* 1-统计字符串 *n"); printf("* 2-删除字符串 *n"); printf("* 0-退出 *n"); printf("*n"); do printf("请输入你要选择的操作: "); scanf("%d",&operate); switch(operate) 沈 阳 大 学课程设计说明书 NO.10case 1: printf("请输入要统计的字符串:"); scanf("%s",&str1);printf("%s出现的次数为:%d n",str1,FindString(head,str1); printf("n");CountAll(head); CountNumber(head);CountLetter(head);CountSpace(head); break; case 2: printf("请输入要删除的某一字符串:"); scanf("%s",&str2); DelString(head,str2);printf("删除%s后的文章为:n",str2);OutPut(head); break; case 0: ;break; while(operate!=0); 沈 阳 大 学课程设计说明书 NO.113、课程设计运行结果与分析图3:初始界面 沈 阳 大 学课程设计说明书 NO.12图4:运行界面 沈 阳 大 学课程设计说明书 NO.13输入1:统计字符数图5:统计字符界面 沈 阳 大 学课程设计说明书 NO.14输入2:删除字符图6:删除字符 沈 阳 大 学课程设计说明书 NO.15输入0:退出程序图7:退出程序 沈 阳 大 学课程设计说明书 NO.164、课程设计体会此次课程设计使我对数据结构方面的知识有了更加深入的了解,也使我认识到自己在学习编程方面还有很多的不足。今后我要多读一些编程方面的书籍,不能只拘泥于课本上的知识,并注重理论与实践的结合,多上机练习编写程序,提高自己的实际动手能力和独立思考的能力,不断充实自己,更好的掌握编程思想。参考文献1 谭浩强.C语言程序设计M.北京清华大学出版社,2007.05:1-2002徐孝凯,魏荣数据结构,机械工业出版社,1996年:1-1503徐孝凯数据结构简明教程,清华大学出版社,1995年:75-1204陈文博,朱青数据结构与算法,机械工业出版社,1996年 :80-1005李廉治,姜文清,郭福顺数据结构,大连理工大学出版社,1989年:120-200 沈 阳 大 学