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

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

程序设计报告

(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)查找功能:

图二:查找功能图

开始

申请访问

输入要查找的字符

判断是否存在

记录位置

输出

结束

开始

创建空间

输入要插入的字符或

字符串

输入要插入的位置

计算出插入字符串的

长度n

将要插入位置之后

的字符串向后移n

插入要插入的字

符或者字符串

结束

图三:插入功能图

开始

输入字符串

查找所输入字符串所在的位置

能否找到

将其后字符串向前移动覆盖之

结束否

图四:删除功能图

开始

申请访问

输入要统计的内

查找符合条件的字符字

符统计个数

输出统计个数

结束

图五:统计功能图四源程序代码

#include

#include

#include

#include

#include

#include

#include

using namespace std;

#define Link_Size 100

int NUM,C,N;

typedef struct list

{

char data[80];

int length;

struct list *next;

struct list *pre;

int row;

} LinkList;

LinkList *head;

void HeadWord()

{

// system("cls");

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

LinkList *LoadWord()

{

LinkList *temp;

char ch;

int i,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';

}

ofstream ocout;

ocout.open("f://text.txt",ios::app);

ocout<data;

ocout.close();

LinkList *temp;

char ch; temp->row=NUM+1;

system("cls");

return temp;

}

LinkList *CreatWord()

{

int i,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';

}

ofstream ocout;

ocout.open("f://text.txt");

ocout<data;

ocout.close();

temp->row=NUM+1;

system("cls");

return temp;

}

void PrintWord()

{

ifstream icin;

icin.open("f://text.txt");

char tt[100]={0};

icin.getline(tt,100,0);

cout<

}

void CountWord()

{

LinkList *temp;

char ch;

int i,j,t;

int WORD=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++;

else if((ch>='a')&&(ch<='z'))

word++;

else if((ch>='0')&&(ch<='9'))

num++;

else if(ch==' ')

space++;

else if(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)

{

case 1:

system("cls");

HeadWord();

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

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

getchar();

getchar();

system("cls");

break;

case 2:

system("cls");

HeadWord();

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

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

getchar();

getchar();

system("cls");

break;

case 3:

system("cls");

HeadWord();

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

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

getchar();

getchar();

system("cls");

break;

case 4:

system("cls");

HeadWord();

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

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

getchar();

getchar();

system("cls");

break;

case 5:

system("cls");

HeadWord();

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

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

getchar();

getchar();

system("cls");

break;

case 6:

system("cls");

HeadWord();

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

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

getchar();

getchar();

system("cls");

break;

}

if(t==7)

{system("cls"); break;}

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

}

}

void SearchWord(char *str1,LinkList* temp)

{

char Data[20] ;

int i,j,k=0,sum=0;

int l=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++;

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

{

j=j-k;

k=0;

}

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

{

sum++;

j=j-k+1;

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

k=0;

continue;}

}

temp=temp->next;

}

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

C=sum;

N=i*80+j;

}

void DeleteWord(char *str2)

{ char Data[20];

LinkList *temp,*term;

int i,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++;

else if(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)

{

char Data[20];

int h,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);

int i=(h-1)*80+l;

LinkList *a;

int n=strlen(Data);

int m ;

int insertRow=i/80+1;

int row=temp->row;

int j;

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

{

int r=0;

for(int p=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];

}

return temp;

}

void Bmenu(LinkList *temp)

{

char str1[20];

char str2[20];

int a;

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)

{

case 1:

system("cls");

HeadWord();

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

getchar();

gets(str1);

SearchWord(str1,temp);

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

getchar();

getchar();

system("cls");

break;

case 2:

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;

case 3:

system("cls");

HeadWord();

InsertWord(temp);

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

PrintWord();

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

getchar();

getchar();

system("cls");

break;

case 4:

system("cls");

HeadWord();

PrintWord();

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

getchar();

getchar();

system("cls");

break;

}

if(a==5)

{

system("cls");

break;

}

if(a==6) exit(0);

}while(1);

}

void AboutWord()

{

cout<<"\n\n\t\t 关于\n";

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

cout<<"\t\t** 谢谢使用**\n";

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

cout<<"\n";

}

void menu(LinkList *temp)

{

int t;

do{

HeadWord();

printf("\n");

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****************************************************\n";

cout<<"\t\t**** 注:第一次运行本程序时请选择1号功能****\n";

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

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

cin>>t;

if((t>6)&&(t<1))

{

cout<<"对不起,无此功能,请输入正确的功能序号!\n";

}

else

switch(t)

{

case 1:

system("cls");

cout<<"\t\t************继续上次输入还是重新输入?*************"<

cout<<"\t\t*******1:继续输入***********2:重新输入*********\n";

int s;

cin>>s;

switch(s)

{

case 1:

HeadWord();

temp=LoadWord();

break;

case 2:

HeadWord();

temp=CreatWord();

文本编辑器c++实验报告附源代码

四川大学软件学院 实验报告 课程名称数据结构实验课时8 实验项目文本编辑器实验时间12到14周实验目的了解c++类的封装和KMP算法。 实验环境 Windows平台 VC6.0++ 实验内容(算法、程序、步骤和方法) 部分函数创建思想: 创建过程如下: a、定义LinkList指针变量*temp: LinkList *temp; b、定义文本输入变量ch,记录文本行数变量j,记录每行字符数变量i; c、申请动态存储空间:head->next=(LinkList *)malloc(sizeof(LinkList)); d、首行头指针的前驱指针为空:head->pre=NULL; 首行指针:temp=head->next; 首行指针的前驱指针也为空:temp->pre=NULL; 定义没输入字符时文章长度为0:temp->length=0; 初始化为字符串结束标志,防止出现乱码:for(i=0;i<80;i++) temp->data[i]='\0'; e、利用循环进行文本输入 for(j=0;jdata[i]=ch; //给temp指向的行赋值 ···· temp->length++;//行中字符长度加1 if(ch=='#') {NUM=j; break; //文章结束时,Num来记录整个文章的行数 }}} 在字符输入的过程中,如果在单行输入的字符超过了80个字符, 则需要以下操作: 输入字符数大于80,重新分配空间建立下一行 temp->next=(LinkList *)malloc(sizeof(LinkList)) ;

几种常用网页文本编辑器总结

文本编辑器应用总结 一.lhgeditor文本编辑器 lhgeditor组件文件结构: 1. lhgeditor.js:组件的核心JS文件 2. lhgeditor.css:组件的样式表文件 3. images:组件所需的图片都在此文件夹中 以上三个文件为组件所必须的三个文件,组件包中其它以“_”开头的文件为示例的演示文件,实际使用中不需要这些文件。当然框架核心文件lhgcore.js是每个组件都必须用到的文件,记得加载组件前先要加载此文件。 lhgeditor组件使用说明: 1. 在调用组件的页面加载lhgcore.j s和lhgeditor.js两个文件。 2. 在window.onload函数里加入J.editor.add(编辑器的id).init(); 例:

二.nicEdit文本编辑器