数据结构课程设计_第1页
数据结构课程设计_第2页
数据结构课程设计_第3页
已阅读5页,还剩21页未读 继续免费阅读

下载本文档

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

文档简介

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

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

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

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

5、/输入字符串! */printf(”每行最多输入80字符”);break;if(ch0=5)break; /*p=p->n ext =new LINE;p->data=new charstrle n( ch)+1; strcpy(p_>data,ch);if(chstrle n( ch)-1=5)/*p->datastrle n( ch)_1='0:break;p-> next=NULL;/*head=head->n ext;如果发现输入AE,则退出输入*/*为结点分配空间*/除去最后一个控制符ae */最后的一个指针为空*/*文本字数统计*/int

6、 Cou nt_Space(LINE* & head)/统计空格数LINE *p=head;int asc_space=32;int coun t=0;int i;int Len;doLen=strle n( p->data);for(i=0;i<Le n;i+) if(p->datai=asc_space)coun t+;while(p=p-> next)!=NULL);retur n count;int Cou nt_Num(LINE * & head)/ 统计数字个数LINE *p=head;int coun t=0;int Len;int i;d

7、oLen=strle n( p->data);for(i=0;i<Le n;i+)if(p->datai>=48 && p->datai<=57) coun t+;while(p=p-> next)!=NULL);retur n count;int Cou nt_AII_Word(LINE * & head)/统计文章的总字数LINE *p=head;int coun t=0;docoun t+=strle n( p->data);whiIe(p=p-> next)!=NULL);retur n count;int

8、Cou nt_Letter(LINE * & head)/ LINE *p=head;int coun t=0;int Len;统计字母数int i;doLen=strle n( p->data);&& p->datai<='z'|p->datai>='A'计算字母个数&&for(i=0;i<Le n;i+) if(p->datai>='a' p->datai<='Z')cou nt+; / whiIe(p=p-> next)

9、!=NULL); retur n count;统计sch在文章中出现的次int Fin d_Word(LINE * & head,char *sch)数LINE *p=head;int coun t=0;int len 1=0;int len 2=strle n( sch);int i,j,k;dolen 1=strle n(p->data); 当前行的字符数 for(i=0;i<le n1;i+)if(p->datai=schO)k=0;for(j=0;j<=le n2-1;j+) if(p->datai+j=schj)k=k+1; if(k=len2)

10、 count+;i=i+k-1; while(p=p-> next)!=NULL);retur n count;/*特定字符串的删除*/void del_stri ng_word(char *s,char *sch)char *p=strstr(s,sch);char tmp80;int len=strle n(s);int k,kk;int i=le n-strle n( p);int j=i+strle n( sch);int coun t=0;for(k=0;k<i;k+)tmpco un t+=sk;for(kk=j;kk<le n;kk+)tmpco un t+=s

11、kk;tmpcou nt='O:strcpy(s,tmp);void Del_Stri ng(LINE * & head,char *sch)删除指定的字符串LINE *p=head;dowhile(strstr(p->data,sch)!=NULL)del_stri ng_word(p->data,sch);while(p=p-> next)!=NULL);/*特定字符串的替换*/void replace_stri ng_word(char *s,char *sch,char *reh)int Strin gLe n;char caNewStri ng100

12、;char *Fin dPos = strstr(s, sch);/if(!Fi ndPos) | (!sch)/return -1;while(Fi ndPos)memset(caNewStri ng, 0, sizeof(caNewStri ng);Stri ngLe n = Fin dPos - s;strncpy(caNewString, s, StringLen);strcat(caNewStri ng, reh);strcat(caNewStri ng, Fin dPos + strle n( sch);strcpy(s, caNewStri ng);Fin dPos = strs

13、tr(s, sch);/* return 0;*/替换指定的void Replace_Stri ng(LINE * & head,char *sch,char *reh) 字符串LINE *p=head;dowhile(strstr(p->data,sch)!=NULL) replace_stri ng_word(p->data,sch,reh);while(p=p-> next)!=NULL);/*打印输入的文本*/void OutPutTxt(LINE * & head)/向屏幕输出文章LINE *p=head;prin tf("文本文件输出如下

14、:");doprin tf("%sn",p->data);while(p=p-> next)!=NULL);void Cou nt(LINE * &head)printf("文章统计信息结果:n");prin tf("全部字母数:%dn ”,Cou nt_Letter(head);printf("数字个数:%dn",Cou nt_Num(head);printf("空格个数:%d n",Count_Space(head);prin tf("文章总字数:%dn&quo

15、t;,(Cou nt_AII_Word(head)+Cou nt_Num(head)+Cou nt_Space(head)+Co un t_Letter(head)/2);prin tf("n");void mai n()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 para

16、meters 错误类型:Search函数参数错误改正方法:将case语句后加break语句进行返回。(2) 错误提示:error C2228: left of '.search' must have class/struct/u nio n type 错误类型:指针符号使用错误改正方法:将 s.Search(stu,s) 更改为 s->search(stu,s)(3) 错误提示:error C2676: binary '>>' : 'class std:basic_ofstream<char,struct std:char_tra

17、its<char> >' does not define this operator or a conversion to a type acceptable to the predefi ned operator错误类型:文件流输入输出符号使用错误,错误使用 >>作为文件写入操作符。 改正方法:将 >>改为<<。4测试结果测试项目测试数据测试结果登陆界面1. 新建文本2. 浏览输入文本3. 文本字符统计4. 指定字符串统计5. 指定字符串删除6. 指定字符串替换7. 退出显示:1. 新建文本2. 浏览输入文本3. 文本字符统计4.

18、 指定字符串统计5. 指定字符串删除6. 指定字符串替换7. 退出新建功能输入1:新建文本Abcdefg 1234567显示:Abcdefg 1234567显示功能输入2:浏览输入文本显示用户录入结果:Abcdefg 1234567统计功能输入3:文本字符统计文章统计信息结果:全部字母数:7 数字个数:7 空格个数:1 文章总字数:15指定字符串统计功能输入4 :指定字符串删除 输入要统计字符串:Ab出现次数:1指定字符串删 除功能输入5 :指定字符串删除 输入要删除字符串:Ab删除后文本文件如下:cdefg 1234567指定字符串替换功能输入6 :指定字符串替换 要替换掉的字符串:cdef

19、g 要替换成的字符串:!替换后文本文件如下:!12345675使用说明本系统开始时显示所有选择项。选择项采用文字提示,数字选择进行选择 操作。图5.1显示运行界面录入选项: 输入1 :新建文本g "C:M>ocu»ents and SetlinssFSILE|Dehiis2ll 120233lHi267-王苍岂一文卓圻辑- alskdjf klasdjfdklfjdsJ<32113123jJ输入2:浏览输入文本图5.3浏览输入文本界面输入3:文本字符统计图5.4文本字符统计界面输入4:指定字符串统计g "C:tocuBents and SetlinEs

20、VFSlX桌IBKDetn吃、2II 12(23引】巾2毎-王苍穹一文卓<5辑- 请输入君统计痔甌"文本文件输出如下=rtlskdjf klasdjfdklfJdsk32113123出现的次数为二2jv*v<wrvrvrwvnjmmmjTWiKn%JYWwsmjwwMwnmvwwvwwwvYww«v«v«vfvrvrwvwnjmjTKmjwiWHmjwYsmjw#Mwnmvwwvwww>mnrw1新建文本£浏览输入文本芥文本字符统计4一指定字符串的统计5指定字符串的删除氣指定字符串的替换7退出MM :M M M M M M K

21、 H KKK K KK HHKltMWMM M MMM M M M MMM M M M M M M K KKKK K K KHHM M MMMM MMM M M M M M请输入助能序号:图5.5指定字符串统计界面输入5:指定字符串删除g "C:DocuBents and SetlmeijFSI桌IEKDrIh吃t2(H2D23引】丨2眉-王苍岂一3t章圻辑-请输入要删除的某一字符串:已 文本文件输出如下:dlskdjf klasdjfdklfJdsk32113123删涂启文本文件输岀如下:lskdjf klsajfiklf jilsk32113123jwvfVfVfvrMwwnmj

22、TwrwiaknHmmmjYxnnnnnnHwnmwvwwHwww'iWfVfVfVfvrMrvwwnmjTKnwwiPknMwuwuYuvwwwmvwnmwvwwmwvww1新建文本£游览输入文 齐文本字符统4一指定字椅串指定字符串 氣指定字符阳7.退请输入助能序号:输入6:指定字符串替换5 -C:M>Qoi.ent5 and SettLK£»RSI桌iflUJftln吃说0 1加2幻0圾眉-王苍穹-交卓编辑 83田|lskdjf kLsdjFdklfjdsk32113123 请输入要替换成的字符$S ?文本文件输出如下*lshdjf klsdjf

23、dklfJdsk32113123替换后文本文件输岀如下'lstdjf lsdjfa*Ifjds132113123fVirvfvrvfvrvrvnjmnwwMYWWsmmjwsrwsnrsrvsmmrvwwvwrwmwHrYwrwfViivrvrvrvrvrvnjmnwMWYWWAmjwsrwsnrsrwrrwvwvwrwmwwrarYV1新建文本直制览输入文本筑文本字符统计4.指定宇符串的统计9扌旨定字符串的删除筑抱定字符串的替换7退出请愉人功能序号.图5.7指定字符串替换界面输入7:退出悴and SettinjsFSI桌nltDRtn吃说(|12123:勺012&丁一王苍岂一

24、丈章36辑-文本文件输出如下*lskdjf kLsdJfdklf.idsK32113123替换后文本文件输岀如下lstdjf *lsdJFd»Lfjds!321131231新建文本2浏览输入文本齐文本字符统计4一指定字符串的统计畀指定字符串的删除&扌旨定字符串的替换?退出图5.8退出界面6总结感谢老师的指导和讲解。通过老师的讲解,让我对这门课程有了深刻的认 识和了解,也让我对这门课程有了重新的认识。通过近两周的课程设计中, 我学到了数据结构程序设计中对类的设计方法, 及对磁盘文件的操作,从中理解了数据结构中的设计思想。经过这次集中上机 实习,我充分意识到了数据结构的用途是非常

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

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

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

28、 &head)/ 统计空格数LINE *p=head;int asc_space=32;int coun t=0;int i;int Len;doLen=strle n( p->data);for(i=0;i<Le n;i+) if(p_>datai=asc_space)coun t+;while(p=p-> next)!=NULL);retur n count;int Cou nt_Num(LINE * & head)/ 统计数字个数LINE *p=head;int coun t=0;int Len;int i;doLen=strle n( p->

29、;data);for(i=0;i<Le n;i+) if(p->datai>=48 && p->datai<=57) coun t+;while(p=p-> next)!=NULL);retur n count; int Cou nt_AII_Word(LINE * & head)/ 统计文章的总字数 LINE *p=head;int coun t=0;docoun t+=strle n( p->data);while(p=p-> next)!=NULL);retur n count;int Cou nt_Letter(L

30、INE * & head)/ 统计字母数LINE *p=head;int coun t=0;int Len;int i;doLen=strle n( p->data);for(i=0;i<Le n;i+)&&if(p->datai>='a' &&p->datai<='z'|p->datai>='A'p->datai<='Z')cou nt+;/ 计算字母个数while(p=p-> next)!=NULL);retur n co

31、unt;int Find_Word(LINE * &head,char *sch) 统计 sch 在文章中出现的次数LINE *p=head;int coun t=0;int len 1=0;int len 2=strle n( sch);int i,j,k;dolen 1=strlen(p->data); 当前行的字符数for(i=0;i<le n1;i+)if(p->datai=schO)k=0;for(j=0;j<=le n2-1;j+)if(p_>datai+j=schj)k=k+1;if(k=len2) count+;i=i+k-1;while(

32、p=p-> next)!=NULL);retur n count;/*特定字符串的删除*/void del_stri ng_word(char *s,char *sch)char *p=strstr(s,sch);char tmp80;int len=strle n(s);int k,kk;int i=le n-strle n( p);int j=i+strle n( sch);int coun t=0;for(k=0;k<i;k+)tmpco un t+=sk;for(kk=j;kk<le n;kk+)tmpco un t+=skk;tmpcou nt='O'

33、;strcpy(s,tmp);void Del_Stri ng(LINE * & head,char *sch)删除指定的字符串LINE *p=head;do while(strstr(p->data,sch)!=NULL) del_stri ng_word(p->data,sch);while(p=p-> next)!=NULL); /*特定字符串的替换*/void replace_stri ng_word(char *s,char *sch,char *reh)int Strin gLe n;char caNewStri ng100;char *Fin dPos

34、= strstr(s, sch);/if(!Fi ndPos) | (!sch)/return -1;while(Fi ndPos)memset(caNewStri ng, 0, sizeof(caNewStri ng);Stri ngLe n = Fin dPos - s;strncpy(caNewString, s, StringLen);strcat(caNewStri ng, reh);strcat(caNewStri ng, Fin dPos + strle n( sch); strcpy(s, caNewStri ng);Fin dPos = strstr(s, sch);/* r

35、eturn 0; */void Replace_Stri ng(LINE * & head,char *sch,char *reh)替换指定的字符串LINE *p=head;dowhile(strstr(p->data,sch)!=NULL)replace_stri ng_word(p->data,sch,reh);while(p=p-> next)!=NULL);/*打印输入的文本*/void OutPutTxt(LINE * & head)/向屏幕输出文章LINE *p=head;printf("文本文件输出如下:”);doprin tf(&qu

36、ot;%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);prin tf("文章总字数:%dn",(Count_AII_Word(head)+Co

37、unt_Num(head)+Count_Space(head)+Count _Letter(head)/2);prin tf("n"); void mai n()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("printf(”2012023301267while(1)printf(

38、"学号:n"); n");printf(”n ”);printf(”n ”);printf(”n ”);printf(”n ”);printf(”n ”);printf("n ”);printf("n ”);printf("n ”);printf("n ”);printf("n ”);printf("n ”);printf("n ”);printf("n ”);printf("n ”);printf(”1新 建 文 本2浏览输入文本3文本字符统计4.指定字符串5.指定字符串6

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

温馨提示

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

评论

0/150

提交评论