数据结构课程设计文章编辑附录中有全部代码_第1页
数据结构课程设计文章编辑附录中有全部代码_第2页
数据结构课程设计文章编辑附录中有全部代码_第3页
数据结构课程设计文章编辑附录中有全部代码_第4页
数据结构课程设计文章编辑附录中有全部代码_第5页
已阅读5页,还剩30页未读 继续免费阅读

下载本文档

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

文档简介

1、课程设计任务书专业名称:计算机科学与技术(软件工程)课程名称:数据结构课程设计设计题目:文章编辑问题起止时间:2013 年 6 月 24 日至 2013 年 7 月 12 日问题描述静态存储一页文章,每行最多不超过80 个字符,共N 行,程序可以统计出文字、数字、 空格的个数,并且可以对文章中特定内容进行查找及替换,同时也可以删除指定内容。基本要求( 1)分别统计出其中英文字母数和空格数及整篇文章总字数;( 2)统计某一字符串在文章中出现的次数,并输出该次数;( 3)查找出文章中某一段文字,并用其他文字进行替换;( 4)删除某一子串,并将后面的字符前移。输出形式:( 1)分行输出用户输入的各行

2、字符;( 2)分4 行输出 " 全部字母数" 、 " 数字个数 " 、 " 空格个数 " 、 " 文章总字数" ;( 3)查找出指定字符串在文章中出现的所有地方并替换,输出替换后结果;( 4)输出删除某一字符串后的文章;实现提示存储结构使用线性表,分别用几个子函数实现相应的功能,并且使用菜单的形式,可以选择所要进行的操作(查找、替换、删除、统计等)文章编辑系统1 概要设计本次课程设计的题目是文章编辑系统,本系统的功能描述如下:用户新建文本、浏览新建文本、文本字符统计、指定字符串统计、指定字符串删除、指定字符串替换等

3、操作。1. 新建文本2. 浏览输入文本3. 文本字符统计4. 指定字符串统计5. 指定字符串删除6. 指定字符串替换7. 退出系统本系统包含七个功能模块,分别为: 新建文本模块,浏览输入文本模块,指定字符串统计模块,指定字符串删除模块,指定字符串删除模块,指定字符串替换模块以退出系统模块。新建文本模块实现用户录入文本信息,并且系统自动保存录入信息。浏览输入文本模块实现 了显示用户录入信息的功能。指定字符申统模块实现了对英文字母数 和空格数及整篇文章总字数的统计。指定字符串统计实现了统计用户 自定义字符串个数的功能。指定字符串删除模块实现了对用户自定义 字符串的删除。指定字符串替换模块实现了替换

4、用户自定义字符串为 用户定义的新字符功能。退出系统模块实现了退出系统功能。图1.1系统功能模块图2详细设计这部分详细介绍了系统中主要部分的功能实现,以及代码功能说明void Create(LINE * &head)printf (" 请输入一页文章,以Ctrl+E 为结尾 (每行最多输入80 字符 !):n");/Ctrl+E 结束文本录入,避免发生混淆LINE *p=new LINE;头结点*/head=p;头指针*/char ch100;while(1)gets(ch);符串! */if(strlen(ch)>80)/* 首先为链表建立一个附加表/*将 p

5、 付给 表/*输入字printf(" 每行最多输入80 字符 ");break;if(ch0=5)break; /*如果发现输入AE,则退*/p=p->next=new LINE;p->data=new charstrlen(ch)+1;/*为结点分配空间 */strcpy(p->data,ch);if(chstrlen(ch)-1=5) /*除去最后一个控制符 AE */p->datastrlen(ch)-1='0'break;p->next=NULL;/*最后的一个指针为空 */head=head->next;/* 文

6、本字数统计*/int Count_Space(LINE* &head)/ 统计空格数LINE *p=head;int asc_space=32;int count=0;int i;int Len;doLen=strlen(p->data);for(i=0;i<Len;i+)if(p->datai=asc_space)count+;while(p=p->next)!=NULL);return count;int Count_Num(LINE * &head)/ 统计数字个数LINE *p=head;int count=0;int Len;int i;doL

7、en=strlen(p->data);for(i=0;i<Len;i+)if(p->datai>=48 && p->datai<=57)count+;while(p=p->next)!=NULL);return count;int Count_All_Word(LINE * &head)/ 统计文章的总字数LINE *p=head;int count=0;docount+=strlen(p->data);while(p=p->next)!=NULL);return count;int Count_Letter(LIN

8、E * &head)/ 统计字母数LINE *p=head;int count=0;int Len;int i;doLen=strlen(p->data);for(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 Fin

9、d_Word(LINE * &head,char *sch)/ 统计 sch 在文章中出现的次数LINE *p=head;int count=0;int len1=0;int len2=strlen(sch);int i,j,k;dolen1=strlen(p->data);/ 当前行的字符数for(i=0;i<len1;i+)if(p->datai=sch0)k=0;for(j=0;j<=len2-1;j+)if(p->datai+j=schj)k=k+1;if(k=len2) count+;i=i+k-1;while(p=p->next)!=NU

10、LL);return count;/* 特定字符串的删除*/void del_string_word(char *s,char *sch)char *p=strstr(s,sch);char tmp80;int len=strlen(s);int k,kk;int i=len-strlen(p);int j=i+strlen(sch);int count=0;for(k=0;k<i;k+)tmpcount+=sk;for(kk=j;kk<len;kk+)tmpcount+=skk;tmpcount='0'strcpy(s,tmp);void Del_String(L

11、INE * &head,char *sch)/ 删除指定的字符串LINE *p=head;dowhile(strstr(p->data,sch)!=NULL) del_string_word(p->data,sch);while(p=p->next)!=NULL);/* 特定字符串的替换*/void replace_string_word(char *s,char *sch,char *reh)int StringLen;char caNewString100;char *FindPos = strstr(s, sch);/ if(!FindPos) | (!sch)

12、/return -1;while(FindPos)memset(caNewString, 0, sizeof(caNewString);StringLen = FindPos - s;strncpy(caNewString, s, StringLen); strcat(caNewString, reh);strcat(caNewString, FindPos + strlen(sch);strcpy(s, caNewString);FindPos = strstr(s, sch);/* return 0;*/void Replace_String(LINE * &head,char *

13、sch,char *reh)/换指定的字符串LINE *p=head;dowhile(strstr(p->data,sch)!=NULL)replace_string_word(p->data,sch,reh);while(p=p->next)!=NULL);/* 打印输入的文本*/void OutPutTxt(LINE * &head)/ 向屏幕输出文章LINE *p=head;printf(" 文本文件输出如下:");doprintf("%sn",p->data);while(p=p->next)!=NULL);

14、void Count(LINE * &head)printf(" 文章统计信息结果:n");printf(" 全部字母数:%dn",Count_Letter(head);printf(" 数字个数:%dn",Count_Num(head);printf(" 空格个数: %d n",Count_Space(head);printf("文章总字数 : %dn",(Count_All_Word(head)+Count_Num(head)+Count_Space( head)+Count_Let

15、ter(head)/2);printf("n");void main()LINE *head;char sch20;char reh20;char ID10;char ch;char tmp_sch20;char tmp_rch20;3 调试报告在本次程序设计中,在编译过程中,出现了几次问题( 1)错误提示:error C2660: 'search' : function does not take1 parameters错误类型:Search 函数参数错误改正方法:将case 语句后加break 语句进行返回。( 2)错误提示:error C2228: l

16、eft of '.search' must haveclass/struct/union type错误类型:指针符号使用错误 改正方法:将 s.Search(stu,s) 更改为 s->search(stu,s)(3 ) 错误提示:error C2676: binary '>>' : 'classstd二basic_ofstream<char,structstd:char_traits<char> >does not define this operator or a conversion to a type a

17、cceptable to the predefined operator错误类型:文件流输入输出符号使用错误,错误使用 >>乍为文件写 入操作符。改正方法:将 >>改为<<。4测试结果测试项目测试数据测试结果登陆界面1.新建义本显示:2.浏览输入义本1.新建义本3.文本字符统计2.浏览输入义本4.指定字符用统计3.文本字符统计5.指定字符串删除4.指定字符用统计6.指定字符串替换5.指定字符串删除7.退出6.指定字符串替换7.退出新建功能输入1:新建义本Abcdefg 1234567显示:Abcdefg 1234567显示功能输入2:浏览输入义本显示用户录入

18、结果:Abcdefg 1234567统计功能输入3:文本字符统计文章统计信息结果:全部字母数:7数字个数:7空格个数:1文草思子数:15指定字符串统计功能输入4:指定字符串删除输入要统计字符串:Ab出现次数:1指定字符串删除功能输入5:指定字符串删除输入要删除字符串:Ab删除后文本文件如下:cdefg 1234567指定字符串替换功能输入6:指定字符串替换要替换掉的字符串:cdefg要替换成的字符串:!替换后文本义件如下:! ! ! ! 12345675使用说明本系统开始时显示所有选择项。选择项采用文字提示,数字选择进行选择操作。图5.1显示运行界面录入选项:输入1:新建文本图5.2新建文本界

19、面输入2:浏览输入文本图5.3浏览输入文本界面输入3:文本字符统计图5.4文本字符统计界面输入4:指定字符串统计图5.5指定字符串统计界面输入5:指定字符串删除图5.6指定字符串删除界面输入6:指定字符串替换图5.7指定字符串替换界面输入7:退出5.8 退出界面6 总结感谢老师的指导和讲解。通过老师的讲解,让我对这门课程有了 深刻的认识和了解,也让我对这门课程有了重新的认识。通过近两周的课程设计中,我学到了数据结构程序设计中对类的 设计方法,及对磁盘文件的操作,从中理解了数据结构中的设计思想。 经过这次集中上机实习,我充分意识到了数据结构的用途是非常广的, 功能也非常强大,是学计算机不可缺少的

20、知识;更重要的是,在这次 编程中熟悉了编写一个比较复杂程序的流程,以及发现问题、解决问 题的能力,为了下一次学习一门新的计算机语言做了充分准备。在之 前感觉还是遥不可及的功能,现在可以实现了,这自然要感谢老师和 同学们的热心帮助,这是我得以及时完成这个程序的重要因素。最后 还是要感谢老师对我们孜孜不倦的教导。成绩:预习报告 分,系统 分,课设报告 分,总分 分,总评: 评语:批阅教师签字:年 月 日附录:全部代码#include <string.h> #include <stdio.h> #include <stdlib.h>#include <con

21、io.h>typedef struct linechar *data;struct line *next;LINE;void Create(LINE * &head)printf ("请输入一页文章,以Ctrl+E 为结尾(每行最多输入80字符 !):n");LINE *p=new LINE;/* 首先为链表建立一个附加表头结点 */head=p;/* 将 p 付给表头指针 */char ch100;while(1)gets(ch);/* 输入字符串!*/if(strlen(ch)>80)printf(" 每行最多输入80 字符 ")

22、;break;if(ch0=5)break;/*如果发现输入 AE ,则退出输入 */p=p->next=new LINE;p->data=new charstrlen(ch)+1;/* 为结点分配空间 */strcpy(p->data,ch);if(chstrlen(ch)-1=5)/* 除去最后一个控制符AE*/p->datastrlen(ch)-1='0'break;/* 最后的一个指针为p->next=NULL;空 */head=head->next;/* 文本字数统计*/int Count_Space(LINE* &head

23、)/ 统计空格数LINE *p=head;int asc_space=32;int count=0;int i;int Len;doLen=strlen(p->data);for(i=0;i<Len;i+)if(p->datai=asc_space)count+;while(p=p->next)!=NULL);return count;int Count_Num(LINE * &head)/ 统计数字个数LINE *p=head;int count=0;int Len;int i;doLen=strlen(p->data);for(i=0;i<Len

24、;i+)if(p->datai>=48 && p->datai<=57)count+;while(p=p->next)!=NULL);return count;int Count_All_Word(LINE * &head)/ 统计文章的总字数LINE *p=head;int count=0;docount+=strlen(p->data);while(p=p->next)!=NULL);return count;int Count_Letter(LINE * &head)/ 统计字母数LINE *p=head;int

25、count=0;int Len;int i;doLen=strlen(p->data);for(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 Find_Word(LINE * &head,char *sch)/ 统

26、计 sch 在文章中出现的次数LINE *p=head;int count=0;int len1=0;int len2=strlen(sch);int i,j,k;dolen1=strlen(p->data);/ 当前行的字符数for(i=0;i<len1;i+)if(p->datai=sch0)k=0;for(j=0;j<=len2-1;j+)if(p->datai+j=schj)k=k+1;if(k=len2) count+;i=i+k-1;while(p=p->next)!=NULL);return count;/* 特定字符串的删除*/void de

27、l_string_word(char *s,char *sch)char *p=strstr(s,sch);char tmp80;int len=strlen(s);int k,kk;int i=len-strlen(p);int j=i+strlen(sch);int count=0;for(k=0;k<i;k+)tmpcount+=sk;for(kk=j;kk<len;kk+)tmpcount+=skk;tmpcount='0'strcpy(s,tmp);void Del_String(LINE * &head,char *sch)/ 删除指定的字符串L

28、INE *p=head;dowhile(strstr(p->data,sch)!=NULL)del_string_word(p->data,sch);while(p=p->next)!=NULL);/* 特定字符串的替换*/void replace_string_word(char *s,char *sch,char *reh)int StringLen;char caNewString100;char *FindPos = strstr(s, sch);/if(!FindPos) | (!sch)/return -1;while(FindPos)memset(caNewSt

29、ring, 0, sizeof(caNewString);StringLen = FindPos - s;strncpy(caNewString, s, StringLen);strcat(caNewString, reh);strcat(caNewString, FindPos + strlen(sch);strcpy(s, caNewString);FindPos = strstr(s, sch);/* return 0;*/替换void Replace_String(LINE * &head,char *sch,char *reh)/指定的字符串LINE *p=head;dowh

30、ile(strstr(p->data,sch)!=NULL)replace_string_word(p->data,sch,reh);while(p=p->next)!=NULL);/* 打印输入的文本*/void OutPutTxt(LINE * &head)/ 向屏幕输出文章LINE *p=head;printf(" 文本文件输出如下:");doprintf("%sn",p->data);while(p=p->next)!=NULL);void Count(LINE * &head)printf(&quo

31、t; 文章统计信息结果:n");printf(" 全部字母数:%dn",Count_Letter(head);printf(" 数字个数:%dn",Count_Num(head);printf(" 空格个数: %d n",Count_Space(head);printf("文章总字数 : %dn",(Count_All_Word(head)+Count_Num(head)+Count_Space(head)+Count_Letter(head)/2);printf("n");void

32、main()LINE *head;char sch20;char reh20;char ID10;char ch;char tmp_sch20;char tmp_rch20;printf("n");printf("n");printf("文章编辑系统n");printf("n");printf("n");while(1)printf("printf("n");printf("n");printf("n");printf(&qu

33、ot;2n");printf("n");printf("3n");printf("n");printf("4统计n");1. 新 建 文 本浏览输入文本文本字符统计指定字符串的printf("n");5. 指 定 字 符 串 的删除printf("n");n");printf("替换printf("n");n");printf("n");printf("n");printf(&

34、quot;printf("6. 指 定 字 符 串 的7. 退出*n"printf(" 请 输 入 功 能 序 号: ");scanf("%s",ID);while(1)if(strcmp(ID,"1")=0) printf(" 新建文本要覆盖已有文本,是否继续输入?Y/N ) n");getchar();scanf("%c",&ch);system("cls");if(ch='n'|ch='N')break;else if(ch='y'|ch='Y')Create(head);break;else if(strcmp(ID,"2")=0)system("cls");OutPutTxt(head);break;else if(strcmp(ID,"3")=0)system("cls");OutPutTxt(head);

温馨提示

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

评论

0/150

提交评论