程序设计文本编辑器的设计与实现汇总.docx

上传人:b****6 文档编号:5102972 上传时间:2022-12-13 格式:DOCX 页数:40 大小:505.98KB
下载 相关 举报
程序设计文本编辑器的设计与实现汇总.docx_第1页
第1页 / 共40页
程序设计文本编辑器的设计与实现汇总.docx_第2页
第2页 / 共40页
程序设计文本编辑器的设计与实现汇总.docx_第3页
第3页 / 共40页
程序设计文本编辑器的设计与实现汇总.docx_第4页
第4页 / 共40页
程序设计文本编辑器的设计与实现汇总.docx_第5页
第5页 / 共40页
点击查看更多>>
下载资源
资源描述

程序设计文本编辑器的设计与实现汇总.docx

《程序设计文本编辑器的设计与实现汇总.docx》由会员分享,可在线阅读,更多相关《程序设计文本编辑器的设计与实现汇总.docx(40页珍藏版)》请在冰豆网上搜索。

程序设计文本编辑器的设计与实现汇总.docx

程序设计文本编辑器的设计与实现汇总

 

程序设计报告

(2014/2015学年第一学期)

 

题目:

文档编辑器的设计与实现

 

专业

组长学号姓名

组员学号姓名

指导教师

指导单位

日期

 

组长()

对文件操作功能(查找,删除,插入)的代码编写,报告中概要设计与代码调试问题部分的撰写

组员()

统计功能代码的编写,翻阅书籍查找资料,报告中课程设计总结及需求分析部分的撰写

组员()

可操作的主菜单及主函数部分代码的编写,报告整体的撰写及测试数据及其结果分析,制图等

评分项

优秀优优秀优秀优秀优秀

良好

及格

遵守机房规章制度

上机时的表现

学习态度

程序准备情况

程序设计能力

团队合作精神

课题功能实现情况

算法设计合理性

用户界面设计

报告书写认真程度

内容详实程度

文字表达熟练程度

回答问题准确度

教师签名

年月日

备注

评分等级分为五种:

优秀,良好,中等,及格,不及格

文档编辑器的设计与实现

一课题内容与要求

文档编辑器系统是对一个文本内容进行各种常规操作,例如:

插入、删除、查找、替换等功能。

通过此课题,熟练掌握文本文件的操作及用字符数组来实现字符串操作的功能。

基本要求:

(1)首先文件标准化处理:

如果句子有前导空格和后导空格,则删除这些空格,单词与单词之间只保留一个空格。

(2)统计功能:

可方便地统计出文档中所有出现次数最多和最少的字符串。

(3)查找与替换功能:

能够查找任意一个字符串在文档中出现的次数,并可以选择全部或有选择地将其替换为另一个字符串。

(4)显示功能:

编辑完成后可以显示编辑后的文档。

(5)抽取功能:

根据要求将文件中的某一类字符抽取,并存入另外的文件,如抽取所有的数字、抽取所有的字母等。

二需求分析

 

图一:

文档编辑器系统的功能框架图

(1)提供可操作的主菜单:

输出个菜单,用于显示若干个可选的功能选项。

根据输入的选项来运行不同的功能,运行不同的函数。

(2)进行文本信息的载入:

选择输入方式,输入文本内容,提供可操作文本。

(3)统计数据功能:

输出第二子菜单,用于显示若干个可选的功能选项。

根据输入的选项来运行不同的功能,运行不同的函数。

(4)编辑数据功能:

输出个菜单,用于显示若干个可选的功能选项。

根据输入的选项来运行查找、删除、插入、显示当前文本等不同的功能,运行不同的函数。

(5)退出程序:

退出当前程序。

 

三概要设计

本程序共有11个函数

1、HeadWord()标题函数,即一个输出标题,永远出现在程序的最顶端。

2、CreatWord()文本输入函数,实现对文本的内容进行输入;

3、PrintWord()当前文本内容输出函数,实现文本内容输出;

4、CountWord()文章内容统计函数,文本内容进行统计,包括对文本内容中的大写字母、小写字母、数字、标点符号、空格以及文章所有字数的个数的统计;

5、SearchWord()文章内容查找函数,实现查找部分;

6、DeleteWord()文章内容删除函数,实现删除部分;

7、InsertWord()文章内容插入函数,实现插入部分;

8、Bmenu()第二子菜单函数,实现子菜单功能;

9、AboutWord()显示作者信息的函数;

10、menu()主菜单函数,实现可操作菜单;

11、main()主函数。

(1)查找功能:

 

 

图二:

查找功能图

 

(2)插入功能

 

图三:

插入功能图

 

(3)删除功能

 

图四:

删除功能图

 

(4)统计功能

 

图五:

统计功能图

四源程序代码

#include

#include

#include

#include

#include

#include

#include

usingnamespacestd;

#defineLink_Size100

intNUM,C,N;

typedefstructlist

{

chardata[80];

intlength;

structlist*next;

structlist*pre;

introw;

}LinkList;

LinkList*head;

voidHeadWord()

{

//system("cls");

cout<<"\t\t****************************************************\n";

cout<<"\t\t****欢迎使用简单的文本编辑器****\n";

cout<<"\t\t****************************************************\n";

}

 

LinkList*LoadWord()

{

LinkList*temp;

charch;

inti,j;

head->next=(LinkList*)malloc(sizeof(LinkList));

head->pre=NULL;

temp=head->next;

temp->pre=NULL;

temp->length=0;

for(i=0;i<80;i++)

temp->data[i]='\0';

cout<<"继续上次输入(输入#号结束):

\n";

for(j=0;j

{

for(i=0;i<80;i++)

{

ch=getchar();

temp->data[i]=ch;

temp->length++;

if(ch=='#')

{

NUM=j;

break;

}

}

if(ch=='#')

{

temp->length=i;

temp->next=NULL;

break;

}

temp->next=(LinkList*)malloc(sizeof(LinkList));

temp->next->pre=temp;

temp=temp->next;

for(i=0;i<80;i++)

temp->data[i]='\0';

}

ofstreamocout;

ocout.open("f:

//text.txt",ios:

:

app);

ocout<data;

ocout.close();

LinkList*temp;

charch;temp->row=NUM+1;

system("cls");

returntemp;

}

LinkList*CreatWord()

{

inti,j;

head->next=(LinkList*)malloc(sizeof(LinkList));

head->pre=NULL;

temp=head->next;

temp->pre=NULL;

temp->length=0;

for(i=0;i<80;i++)

temp->data[i]='\0';

cout<<"开始创建文本,请输入文章(输入#号结束):

\n";

for(j=0;j

{

for(i=0;i<80;i++)

{

ch=getchar();

temp->data[i]=ch;

temp->length++;

if(ch=='#')

{

NUM=j;

break;

}

}

if(ch=='#')

{

temp->length=i;

temp->next=NULL;

break;

}

temp->next=(LinkList*)malloc(sizeof(LinkList));

temp->next->pre=temp;

temp=temp->next;

for(i=0;i<80;i++)

temp->data[i]='\0';

}

ofstreamocout;

ocout.open("f:

//text.txt");

ocout<data;

ocout.close();

temp->row=NUM+1;

system("cls");

returntemp;

}

voidPrintWord()

{

ifstreamicin;

icin.open("f:

//text.txt");

chartt[100]={0};

icin.getline(tt,100,0);

cout<

}

voidCountWord()

{

LinkList*temp;

charch;

inti,j,t;

intWORD=0,word=0,space=0,num=0,punct=0,sum=0;

temp=head->next;

for(j=0;j<=NUM;j++)

{

for(i=0;(i<80)&&(temp->data[i])!

='#';i++)

{

ch=temp->data[i];

if((ch>='A')&&(ch<='Z'))

WORD++;

elseif((ch>='a')&&(ch<='z'))

word++;

elseif((ch>='0')&&(ch<='9'))

num++;

elseif(ch=='')

space++;

elseif(ch==33||ch==34||ch==39||ch==44||ch==46||ch==58||ch==59||ch==63)

{punct++;}

}

sum=WORD+word+num;

}

while

(1)

{

cout<<"\n";

HeadWord();

cout<<"\t\t****************************************************\n";

cout<<"\t\t****文章内容统计菜单****\n";

cout<<"\t\t****************************************************\n";

cout<<"\t\t****1、文章中大写字母的个数****\n";

cout<<"\t\t****2、文章中小写字母的个数****\n";

cout<<"\t\t****3、文章中数字的个数****\n";

cout<<"\t\t****4、文章中标点符号的个数****\n";

cout<<"\t\t****5、文章中空格的个数****\n";

cout<<"\t\t****6、文章中所有字数****\n";

cout<<"\t\t****7、退出返回主菜单****\n";

cout<<"\t\t****8、直接退出本系统****\n";

cout<<"\t\t****************************************************\n";

cout<<"\t\t请选择需统计项目:

";

cin>>t;

switch(t)

{

case1:

system("cls");

HeadWord();

cout<<"文章中大写字母的个数:

"<

cout<<"按回车键继续·····";

getchar();

getchar();

system("cls");

break;

case2:

system("cls");

HeadWord();

cout<<"文章中小写字母的个数:

"<

cout<<"按回车键继续·····";

getchar();

getchar();

system("cls");

break;

case3:

system("cls");

HeadWord();

cout<<"文章中数字的个数:

"<

cout<<"按回车键继续·····";

getchar();

getchar();

system("cls");

break;

case4:

system("cls");

HeadWord();

cout<<"文章中标点符号的个数:

"<

cout<<"按回车键继续·····";

getchar();

getchar();

system("cls");

break;

case5:

system("cls");

HeadWord();

cout<<"文章中空格的个数:

"<

cout<<"按回车键继续·····";

getchar();

getchar();

system("cls");

break;

case6:

system("cls");

HeadWord();

cout<<"文章中所有字数:

"<

cout<<"按回车键继续·····";

getchar();

getchar();

system("cls");

break;

}

if(t==7)

{system("cls");break;}

if(t==8)exit(0);

}

 

}

voidSearchWord(char*str1,LinkList*temp)

{

charData[20];

inti,j,k=0,sum=0;

intl=1;

temp=head->next;

strcpy(Data,str1);

for(i=0;i<=NUM;i++)

{

for(j=0;j<80;j++)

{

if((temp->data[j])==Data[k])k++;

elseif(Data[k]!

='\0')

{

j=j-k;

k=0;

}

if(Data[k]=='\0')

{

sum++;

j=j-k+1;

cout<<"\t\t\t第"<

l++;

k=0;

continue;}

}

temp=temp->next;

}

cout<<"\t\t\t字符串总共出现次数为:

"<

C=sum;

N=i*80+j;

}

 

voidDeleteWord(char*str2)

{charData[20];

LinkList*temp,*term;

inti,j,k,m,y,num;

strcpy(Data,str2);

for(y=0;y

{

num=80;

k=0,m=0;

temp=head;

for(i=0;i<=NUM;i++)

{

term=temp;

temp=temp->next;

for(j=0;j<80;j++)

{

if((temp->data[j])==Data[k])k++;

elseif(Data[k]!

='\0'){j=j-k;k=0;}

if(Data[k]=='\0')

{

num=j;

break;

}

}

if(num<80)break;

}

for(;i<=NUM;i++)

{

for(;j<80;j++)

{

if(j+1

{

term->data[80-k+num]=temp->data[j+1];

}

else

temp->data[j-k+1]=temp->data[j+1];

}

term=temp;

temp=temp->next;

j=0;

}

}

}

LinkList*InsertWord(LinkList*temp)

{

charData[20];

inth,l;

cout<<"\t\t请输入要插入的字符或字符串:

"<

getchar();

gets(Data);

printf("\n\t\t当前文章内容为:

");

PrintWord();

printf("\n\t\t请输入要插入的行:

");

scanf("%d",&h);

printf("\n\t\t请输入要插入的列:

");

scanf("%d",&l);

inti=(h-1)*80+l;

LinkList*a;

intn=strlen(Data);

intm;

intinsertRow=i/80+1;

introw=temp->row;

intj;

if(insertRow==row)

{

for(m=temp->length-1;m>=(i%80)&&n>0;m--)

temp->data[m+n]=temp->data[m];

for(m=(i%80),j=0;m

{

temp->data[m]=Data[j];

}

}

else

{

intr=0;

for(intp=insertRow;p

{

if(p==insertRow)

r=0;

else

r=n;

for(m=temp->length-1-r;m>=0&&n>0;m--)

temp->data[m+n]=temp->data[m];

a=temp;

temp=temp->pre;

temp->length=80;

for(m=temp->length-n,j=0;mlength;m++,j++)

a->data[j]=temp->data[m];

}

for(m=temp->length-n-1;m>=(i%80);m--)

temp->data[m+n]=temp->data[m];

for(m=(i%80),j=0;m<(i%80)+n;m++,j++)

temp->data[m]=Data[j];

}

returntemp;

}

voidBmenu(LinkList*temp)

{

charstr1[20];

charstr2[20];

inta;

do

{

HeadWord();

cout<<"\n\t\t****************************************************\n";

cout<<"\t\t****文章内容处理菜单****\n";

cout<<"\t\t****************************************************\n";

cout<<"\t\t****1、查找文章中的字符或者字符串****\n";

cout<<"\t\t****2、删除文章中的字符或者字符串****\n";

cout<<"\t\t****3、向文章中插入字符或者字符串****\n";

cout<<"\t\t****4、显示当前文章内容****\n";

cout<<"\t\t****5、返回主菜单****\n";

cout<<"\t\t****6、直接退出系统****\n";

cout<<"\t\t****************************************************\n";

cout<<"\t\t请选择:

";

cin>>a;

switch(a)

{

case1:

system("cls");

HeadWord();

cout<<"\t\t\t请输入您需要查找的字符或字符串:

";

getchar();

gets(str1);

SearchWord(str1,temp);

cout<<"按回车键继续·····";

getchar();

getchar();

system("cls");

break;

case2:

system("cls");

HeadWord();

cout<<"\t\t\t请输入您需要删除的字符或字符串:

";

getchar();

gets(str2);

SearchWord(str2,temp);

DeleteWord(str2);

cout<<"\t\t\t删除%s后的文章为:

"<

PrintWord();

cout<<"按回车键继续·····";

getchar();

getchar();

system("cls");

break;

case3:

system("cls");

HeadWord();

InsertWord(temp);

cout<<"\t\t\t插入字符或字符串后文章为:

";

PrintWord();

cout<<"按回车键继续·····";

getchar();

getchar();

system("cls");

break;

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

当前位置:首页 > 高等教育 > 军事

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1