您好,欢迎来到吉趣旅游网。
搜索
您的当前位置:首页文章编辑课设

文章编辑课设

来源:吉趣旅游网
课程设计说明书 NO.1

文章编辑系统 1、课程设计目的 (1)较熟练地掌握C语言的基本内容及程序设计的基本方法与编程技巧。 (2)较熟练地掌握在系统上编辑、编译、连接和运行C程序的方法。 (3)通过设计一个完整程序,掌握数据结构的算法编写、类C语言算法转换成C程序并上机调试的基本方法。 2、课程设计方案论证 2.1 设计思路 (1)定义结构体 struct line,文本行采用顺序存储,行与行之间采用链式存储 统计文字 统计字符 文章编辑系统 删除字符 查找字符 图1:功能模块图 (2)主要函数: int CountNumber(LINE * &head) /*统计数字数*/ 沈 阳 大 学 课程设计说明书 NO.2

开始 *p=head,count=0 int len=str len(p->data) i=0 N idata[i]>=48 && p->data[i]<=57 Y count++ i++ p=p->next N !p=NULL 结束 图2:统计数字函数流程图 沈 阳 大 学 课程设计说明书 NO.3

int FindString(LINE * &head,char *str) /*统计str在文章中出现的次数*/ 开始 count=0;h=0;len1=0; len2=strlen(str); i++ p->data[i]==str[0] N Y k=0;j=0; N p->data[i+j]==str[j] Y k++;j++; N k=len2 Y count++; i=i+k-1; 结束 图3:统计str在文章中的出现次数 沈 阳 大 学 课程设计说明书 NO.4

2.2 源程序清单 #include #include 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 tmp[200]; for(;1;) { gets(tmp); if(strlen(tmp)>80) { printf(\"每行最多输入80字符\"); break; } if(tmp[0]==35)break; p=p->next=(struct line*)malloc(sizeof(struct line)); p->data=(char*)malloc(strlen(tmp)); strcpy(p->data,tmp); if(tmp[strlen(tmp)-1]==35) { p->data[strlen(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;idata[i]>='a'&&p->data[i]<='z')||(p->data[i]>='A'&&p->data[i]<='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;idata[i]>=48 && p->data[i]<=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;idata[i]==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.7

int 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;idata[i]==str[0]) { k=0; for(j=0;jdata[i+j]==str[j]) 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.8

char tmp[80]; int len=strlen(s); int i=len-strlen(p); int j=i+strlen(str); int count=0; for(int m=0;mdata,str)!=NULL)delstringword(p->data,str); } while((p=p->next)!=NULL); } void OutPut(LINE * &head) { LINE *p=head; do { printf(\"%s\\n\ } while((p=p->next)!=NULL); 沈 阳 大 学 课程设计说明书 NO.9

void main() { int i=0; int operate; LINE * head; Create(head); printf(\"输入的文章为:\\n\"); OutPut(head); printf(\"\\n\"); printf(\"全部字母数:%d \\n\ printf(\"数字个数:%d \\n\ printf(\"空格个数: %d \\n\ printf(\"文章总字数: %d \\n\ char str1[20],str2[20]; printf(\"\\n\"); printf(\"**********************\\n\"); printf(\"* 菜 单 *\\n\"); printf(\"**********************\\n\"); printf(\"* 1---统计字符串 *\\n\"); printf(\"* 2---删除字符串 *\\n\"); printf(\"* 0---退出 *\\n\"); printf(\"**********************\\n\"); do{ printf(\"请输入你要选择的操作: \"); scanf(\"%d\ switch(operate) { 沈 阳 大 学 课程设计说明书 NO.10

case 1: printf(\"请输入要统计的字符串:\"); scanf(\"%s\printf(\"%s出现的次数为:%d \\n\ printf(\"\\n\"); CountAll(head); CountNumber(head); CountLetter(head); CountSpace(head); break; case 2: printf(\"请输入要删除的某一字符串:\"); scanf(\"%s\ DelString(head,str2); printf(\"删除%s后的文章为:\\n\ OutPut(head); break; case 0: ;break; } }while(operate!=0); } 沈 阳 大 学 课程设计说明书 NO.11

3、课程设计运行结果与分析 图3:初始界面 沈 阳 大 学 课程设计说明书 NO.12

图4:运行界面 沈 阳 大 学 课程设计说明书 NO.13

输入1:统计字符数 图5:统计字符界面 沈 阳 大 学 课程设计说明书 NO.14

输入2:删除字符 图6:删除字符 沈 阳 大 学 课程设计说明书 NO.15

输入0:退出程序 图7:退出程序 沈 阳 大 学 课程设计说明书 NO.16

4、课程设计体会 此次课程设计使我对数据结构方面的知识有了更加深入的了解,也使我认识到自己在学习编程方面还有很多的不足。今后我要多读一些编程方面的书籍,不能只拘泥于课本上的知识,并注重理论与实践的结合,多上机练习编写程序,提高自己的实际动手能力和思考的能力,不断充实自己,更好的掌握编程思想。 参考文献 [1] 谭浩强.C语言程序设计[M].北京清华大学出版社,2007.05:1-200 [2]徐孝凯,魏荣《数据结构》,机械工业出版社,1996年:1-150 [3]徐孝凯《数据结构简明教程》,清华大学出版社,1995年:75-120 [4]陈文博,朱青《数据结构与算法》,机械工业出版社,1996年 :80-100 [5]李廉治,姜文清,郭福顺《数据结构》,大连理工大学出版社,19年:120-200 沈 阳 大 学

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- jqkq.cn 版权所有 赣ICP备2024042794号-4

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务