课程设计任务书专业名称:计算机科学与技术(软件工程)课程名称:数据结构课程设计设计题目:文章编辑问题起止时间:2013年6 月24 日至2013年7 月12 日问题描述静态存储一页文章,每行最多不超过80个字符,共N行,程序可以统计出文字、数字、空格的个数,并且可以对文章中特定内容进行查找及替换,同时也可以删除指定内容。
基本要求(1)分别统计出其中英文字母数和空格数及整篇文章总字数;(2)统计某一字符串在文章中出现的次数,并输出该次数;(3)查找出文章中某一段文字,并用其他文字进行替换;(4)删除某一子串,并将后面的字符前移。
输出形式:(1)分行输出用户输入的各行字符;(2)分4行输出"全部字母数"、"数字个数"、"空格个数"、"文章总字数";(3)查找出指定字符串在文章中出现的所有地方并替换,输出替换后结果;(4)输出删除某一字符串后的文章;实现提示存储结构使用线性表,分别用几个子函数实现相应的功能,并且使用菜单的形式,可以选择所要进行的操作(查找、替换、删除、统计等)。
文章编辑系统1概要设计本次课程设计的题目是文章编辑系统,本系统的功能描述如下:用户新建文本、浏览新建文本、文本字符统计、指定字符串统计、指定字符串删除、指定字符串替换等操作。
1.新建文本2.浏览输入文本3.文本字符统计4.指定字符串统计5.指定字符串删除6.指定字符串替换7.退出系统本系统包含七个功能模块,分别为:新建文本模块,浏览输入文本模块,指定字符串统计模块,指定字符串删除模块,指定字符串删除模块,指定字符串替换模块以退出系统模块。
新建文本模块实现用户录入文本信息,并且系统自动保存录入信息。
浏览输入文本模块实现了显示用户录入信息的功能。
指定字符串统模块实现了对英文字母数和空格数及整篇文章总字数的统计。
指定字符串统计实现了统计用户自定义字符串个数的功能。
指定字符串删除模块实现了对用户自定义字符串的删除。
指定字符串替换模块实现了替换用户自定义字符串为用户定义的新字符功能。
退出系统模块实现了退出系统功能。
图1.1 系统功能模块图2详细设计这部分详细介绍了系统中主要部分的功能实现,以及代码功能说明。
void Create(LINE * &head){printf ("请输入一页文章,以Ctrl+E为结尾(每行最多输入80字符!):\n"); //以Ctrl+E结束文本录入,避免发生混淆LINE *p=new LINE; /*首先为链表建立一个附加表头结点*/ head=p; /*将p付给表头指针*/char ch[100];while(1){gets(ch); /*输入字符串!*/if(strlen(ch)>80){printf("每行最多输入80字符");break;}if(ch[0]==5)break; /*如果发现输入 ^E,则退出输入*/ p=p->next=new LINE;p->data=new char[strlen(ch)+1]; /*为结点分配空间 */ strcpy(p->data,ch);if(ch[strlen(ch)-1]==5) /*除去最后一个控制符 ^E */{p->data[strlen(ch)-1]='\0';break;}}p->next=NULL; /*最后的一个指针为空 */head=head->next;}/**文本字数统计**/int Count_Space(LINE* &head)//统计空格数{LINE *p=head;int asc_space=32;int count=0;int i;int Len;do{Len=strlen(p->data);for(i=0;i<Len;i++)if(p->data[i]==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;do{Len=strlen(p->data);for(i=0;i<Len;i++)if(p->data[i]>=48 && p->data[i]<=57)count++;}while((p=p->next)!=NULL);return count;}int Count_All_Word(LINE * &head)//统计文章的总字数{LINE *p=head;int count=0;do{count+=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;do{Len=strlen(p->data);for(i=0;i<Len;i++)if(p->data[i]>='a' && p->data[i]<='z'||p->data[i]>='A' && p->data[i]<='Z')count++; //计算字母个数}while((p=p->next)!=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;do{len1=strlen(p->data);//当前行的字符数for(i=0;i<len1;i++){if(p->data[i]==sch[0]){k=0;for(j=0;j<=len2-1;j++)if(p->data[i+j]==sch[j])k=k+1;if(k==len2) {count++;i=i+k-1;}}}}while((p=p->next)!=NULL);return count;}/**特定字符串的删除**/void del_string_word(char *s,char *sch){char *p=strstr(s,sch);char tmp[80];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++)tmp[count++]=s[k];for(kk=j;kk<len;kk++)tmp[count++]=s[kk];tmp[count]='\0';strcpy(s,tmp);}void Del_String(LINE * &head,char *sch)//删除指定的字符串{LINE *p=head;do{while(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 caNewString[100];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, FindPos + strlen(sch));strcpy(s, caNewString);FindPos = strstr(s, sch);}/* return 0; */}void Replace_String(LINE * &head,char *sch,char *reh)//替换指定的字符串{LINE *p=head;do{while(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("文本文件输出如下:");do{printf("%s\n",p->data);}while((p=p->next)!=NULL);}void Count(LINE * &head){printf("文章统计信息结果:\n");printf("全部字母数:%d\n",Count_Letter(head));printf("数字个数:%d\n",Count_Num(head));printf("空格个数: %d \n",Count_Space(head));printf("文章总字数: %d\n",(Count_All_Word(head)+Count_Num(head)+Count_Space(head)+Co unt_Letter(head))/2);printf("\n");}void main(){LINE *head;char sch[20];char reh[20];char ID[10];char ch;char tmp_sch[20];char tmp_rch[20];3调试报告在本次程序设计中,在编译过程中,出现了几次问题(1)错误提示:error C2660: 'search' : function does not take 1 parameters错误类型: Search函数参数错误改正方法:将case语句后加break语句进行返回。