数据结构课程设计文章编辑附录中有全部代码精修订.docx

上传人:牧羊曲112 文档编号:4226531 上传时间:2023-04-10 格式:DOCX 页数:53 大小:467.56KB
返回 下载 相关 举报
数据结构课程设计文章编辑附录中有全部代码精修订.docx_第1页
第1页 / 共53页
数据结构课程设计文章编辑附录中有全部代码精修订.docx_第2页
第2页 / 共53页
数据结构课程设计文章编辑附录中有全部代码精修订.docx_第3页
第3页 / 共53页
数据结构课程设计文章编辑附录中有全部代码精修订.docx_第4页
第4页 / 共53页
数据结构课程设计文章编辑附录中有全部代码精修订.docx_第5页
第5页 / 共53页
点击查看更多>>
资源描述

《数据结构课程设计文章编辑附录中有全部代码精修订.docx》由会员分享,可在线阅读,更多相关《数据结构课程设计文章编辑附录中有全部代码精修订.docx(53页珍藏版)》请在三一办公上搜索。

1、 GE GROUP system office room 【GEIHUA16H-GEIHUA GEIHUA8Q8-GEIHUA1688】数据结构课程设计文章编辑附录中有全部代码课程设计任务书专业名称:计算机科学与技术(软件工程) 课程名称:数据结构课程设计设计题目:文章编辑问题起止时间:2013年6 月24 日至2013年7 月12 日问题描述静态存储一页文章,每行最多不超过80个字符,共N行,程序可以统计出文字、数字、空格的个数,并且可以对文章中特定内容进行查找及替换,同时也可以删除指定内容。基本要求(1)分别统计出其中英文字母数和空格数及整篇文章总字数;(2)统计某一字符串在文章中出现的次

2、数,并输出该次数;(3)查找出文章中某一段文字,并用其他文字进行替换;(4)删除某一子串,并将后面的字符前移。输出形式:(1)分行输出用户输入的各行字符;(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; /*将p付给 表头指针*/ char ch100; whi

5、le(1) gets(ch); /*输入字符串!*/ if(strlen(ch)80) printf(每行最多输入80字符); break; if(ch0=5)break; /*如果发现输入 E,则退出输入*/ p=p-next=new LINE; p-data=new charstrlen(ch)+1; /*为结点分配空间 */ strcpy(p-data,ch); if(chstrlen(ch)-1=5) /*除去最后一个控制符 E */ 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;idatai=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;idatai=48 &

7、 p-datainext)!=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 count=0;int Len;int i;doLen=strlen(p-data);for(i=0;idatai=a & p-dataidatai=A & p-dat

8、ainext)!=NULL);return count;int Find_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;idatai=sch0)k=0;for(j=0;jdatai+j=schj)k=k+1;if(k=len2) count+;i=i+k-1;while(p=p-next)!=NULL);return count; /*特定字符

9、串的删除*/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;ki;k+)tmpcount+=sk;for(kk=j;kkdata,sch)!=NULL)del_string_word(p-data,sch);while(p=p-next)!=NULL);/*特定字符串的替换*/void replace_string_word(

10、char *s,char *sch,char *reh) int StringLen; char caNewString100; char *FindPos = strstr(s, sch);/ if(!FindPos) | (!sch) / return -1; while(FindPos) memset(caNewString, 0, sizeof(caNewString);StringLen = FindPos - s;strncpy(caNewString, s, StringLen);strcat(caNewString, reh);strcat(caNewString, FindP

11、os + strlen(sch);strcpy(s, caNewString);FindPos = strstr(s, sch); /* return 0;*/void Replace_String(LINE * &head,char *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

12、*p=head;printf(文本文件输出如下:);doprintf(%sn,p-data);while(p=p-next)!=NULL);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

13、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 take 1 parameters 错误类型: Search函数参数错误 改正方法:将case语句后加break语句进行返回。(2)错误提示: error C2228: left of .search must hav

14、e class/struct/union type错误类型:指针符号使用错误改正方法:将s.Search(stu,s)更改为s-search(stu,s)(3)错误提示:error C2676: binary : class std:basic_ofstreamchar,struct std:char_traits does not define this operator or a conversion to a type acceptable to the predefined operator错误类型:文件流输入输出符号使用错误,错误使用作为文件写入操作符。改正方法:将改为。4测试结果测

15、试项目测试数据测试结果登陆界面1.新建文本2.浏览输入文本3.文本字符统计4.指定字符串统计5.指定字符串删除6.指定字符串替换7.退出显示:1.新建文本2.浏览输入文本3.文本字符统计4.指定字符串统计5.指定字符串删除6.指定字符串替换7.退出新建功能输入1:新建文本Abcdefg 1234567显示:Abcdefg 1234567显示功能输入2:浏览输入文本 显示用户录入结果:Abcdefg 1234567 统计功能输入3:文本字符统计文章统计信息结果:全部字母数:7数字个数:7空格个数:1文章总字数:15指定字符串统计功能输入4:指定字符串删除 输入要统计字符串:Ab出现次数:1指定字

16、符串删除功能输入5:指定字符串删除输入要删除字符串:Ab删除后文本文件如下:cdefg 1234567指定字符串替换功能输入6:指定字符串替换 要替换掉的字符串:cdefg要替换成的字符串:!替换后文本文件如下:! 12345675 使用说明本系统开始时显示所有选择项。选择项采用文字提示,数字选择进行选择操作。图5.1 显示运行界面录入选项:输入1:新建文本图5.2 新建文本界面输入2:浏览输入文本图5.3 浏览输入文本界面输入3:文本字符统计图5.4 文本字符统计界面输入4:指定字符串统计图5.5 指定字符串统计界面输入5:指定字符串删除图5.6 指定字符串删除界面输入6:指定字符串替换图5

17、.7 指定字符串替换界面输入7:退出图5.8 退出界面6总结感谢老师的指导和讲解。通过老师的讲解,让我对这门课程有了深刻的认识和了解,也让我对这门课程有了重新的认识。通过近两周的课程设计中,我学到了数据结构程序设计中对类的设计方法,及对磁盘文件的操作,从中理解了数据结构中的设计思想。经过这次集中上机实习,我充分意识到了数据结构的用途是非常广的,功能也非常强大,是学计算机不可缺少的知识;更重要的是,在这次编程中熟悉了编写一个比较复杂程序的流程,以及发现问题、解决问题的能力,为了下一次学习一门新的计算机语言做了充分准备。在之前感觉还是遥不可及的功能,现在可以实现了,这自然要感谢老师和同学们的热心帮

18、助,这是我得以及时完成这个程序的重要因素。最后还是要感谢老师对我们孜孜不倦的教导。成绩:预习报告 分,系统 分,课设报告 分,总分 分,总评: 评语:批阅教师签字: 年 月 日附录:全部代码 #include #include #include #include typedef struct linechar *data;struct line *next;LINE;void Create(LINE * &head) printf (请输入一页文章,以Ctrl+E为结尾(每行最多输入80字符!):n);LINE *p=new LINE; /*首先为链表 建立一个附加表头结点*/ head=p;

19、 /*将p付给 表头指针*/ char ch100; while(1) gets(ch); /*输入字符串!*/ if(strlen(ch)80) printf(每行最多输入80字符); break; if(ch0=5)break; /*如果发现输入 E,则退出输入*/ p=p-next=new LINE; p-data=new charstrlen(ch)+1; /*为结点分配空间 */ strcpy(p-data,ch); if(chstrlen(ch)-1=5) /*除去最后一个控制符 E */ p-datastrlen(ch)-1=0; break; p-next=NULL; /*最后

20、的一个指针为空 */ head=head-next;/*文本字数统计*/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;idatai=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=strl

21、en(p-data);for(i=0;idatai=48 & p-datainext)!=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 count=0;int Len;int i;doLen=strlen(p-data);for(i=0;ida

22、tai=a & p-dataidatai=A & p-datainext)!=NULL);return count;int Find_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;idatai=sch0)k=0;for(j=0;jdatai+j=schj)k=k+1;if(k=len2) count+;i=i+k-1;while(p=p-nex

23、t)!=NULL);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;ki;k+)tmpcount+=sk;for(kk=j;kkdata,sch)!=NULL)del_string_word(p-data,sch);while(p=p-next)!=NULL);/*特定字符串

24、的替换*/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(caNewString, 0, sizeof(caNewString);StringLen = FindPos - s;strncpy(caNewString, s, StringLen);strcat(caNewString,

25、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;dowhile(strstr(p-data,sch)!=NULL)replace_string_word(p-data,sch,reh);while(p=p-next)!=NULL);/*打印输入的文本*/void OutPutT

26、xt(LINE * &head)/向屏幕输出文章 LINE *p=head;printf(文本文件输出如下:);doprintf(%sn,p-data);while(p=p-next)!=NULL);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(hea

27、d)+Count_Space(head)+Count_Letter(head)/2);printf(n);void 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( n);printf( n);printf( 1. 新 建 文 本 n);printf( n);printf( 2. 浏 览 输 入 文 本 n);prin

28、tf( n);printf( 3. 文 本 字 符 统 计 n);printf( n);printf( 4. 指 定 字 符 串 的 统 计 n);printf( n);printf( 5. 指 定 字 符 串 的 删 除 n);printf( n);printf( 6. 指 定 字 符 串 的 替 换 n);printf( n);printf( 7. 退 出 n);printf( n);printf( *n);printf(请 输 入 功 能 序 号:);scanf(%s,ID);while(1)if(strcmp(ID,1)=0)printf(新建文本要覆盖已有文本,是否继续输入(Y/N)

29、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);printf(n);Count(head);break;else if(strcmp(ID,4)=0)system(cls);printf(请输入要统计的字符串:);scanf(%s,sch);

30、printf(n);OutPutTxt(head);printf(n);printf(出现的次数为: %dn,Find_Word(head,sch);break;else if(strcmp(ID,5)=0)system(cls);printf(请输入要删除的某一字符串:);scanf(%s,tmp_sch);printf(n);OutPutTxt(head);Del_String(head,tmp_sch);printf(删除后);OutPutTxt(head);break;else if(strcmp(ID,6)=0)system(cls);printf(请输入要替换掉的某一字符串:);s

31、canf(%s,tmp_rch);printf(n);OutPutTxt(head);printf(请输入要替换成的字符串:);scanf(%s,reh);printf(n);OutPutTxt(head);Replace_String(head,tmp_rch,reh);printf(替换后);OutPutTxt(head);break;else if(strcmp(ID,7)=0)printf(你确定要退出系统吗(Y/N)n);getchar();scanf(%c,&ch);system(cls);if(ch=n|ch=N)break;else if(ch=y|ch=Y) exit(0);elsesystem(cls);printf(您输入字母有错,请重新输入!nn);break;

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

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号