简单行编辑系统数据结构课程设计说明书.docx

上传人:b****8 文档编号:23853458 上传时间:2023-05-21 格式:DOCX 页数:32 大小:83.91KB
下载 相关 举报
简单行编辑系统数据结构课程设计说明书.docx_第1页
第1页 / 共32页
简单行编辑系统数据结构课程设计说明书.docx_第2页
第2页 / 共32页
简单行编辑系统数据结构课程设计说明书.docx_第3页
第3页 / 共32页
简单行编辑系统数据结构课程设计说明书.docx_第4页
第4页 / 共32页
简单行编辑系统数据结构课程设计说明书.docx_第5页
第5页 / 共32页
点击查看更多>>
下载资源
资源描述

简单行编辑系统数据结构课程设计说明书.docx

《简单行编辑系统数据结构课程设计说明书.docx》由会员分享,可在线阅读,更多相关《简单行编辑系统数据结构课程设计说明书.docx(32页珍藏版)》请在冰豆网上搜索。

简单行编辑系统数据结构课程设计说明书.docx

简单行编辑系统数据结构课程设计说明书

中北大学

数据结构

课程设计说明书

学院:

电子与计算机科学技术学院

专业:

网络工程/计算机科学与技术

题目:

简单行编辑器

指导教师:

潘广贞

组长姓名:

学号

组员姓名:

学号

组员姓名:

学号

组员姓名:

学号

组员姓名:

学号

 

 

 

2012年8月30日

 

1.概述1

1.1设计目的1

1.2设计目标及要求设计要求1

1.3设计进度1

1.4分工1

2.需求分析及总体设计1

2.1数据结构1

2.2功能框架2

3.功能模块详细设计2

3.1设计流程2

3.2主要源代码2

4.功能模块详细设计2

4.1设计流程2

4.2主要源代码3

1.概述

1.1设计目的

被编辑的文本文件可能很大,全部读入编辑程序的数据空间(内存)的作法既不经济,也不总能实现。

所以设计这一种以行为单位进行的编辑程序。

主要是逐段地编辑。

任何时刻只把待编辑文件的一段放在内存,称为活区。

需要用到的数据结构是链表。

1.2设计目标及要求设计要求

(1)行插入:

格式:

i<回车><行号><回车><文本><回车>

功能:

在指定行之后插入一行或几行。

(2)行删除:

格式:

d<回车><行号1>[<空格><行号2>]<回车>

功能:

在指定行之后插入一行或几行。

(3)行替换:

格式:

i<回车><行号><回车><文本><回车>

功能:

在指定行之后插入一行或几行。

(4)活区切换:

格式:

n<回车>

功能:

将活区写入文件,并从文件中读入下一段,作为新的活区。

(5)活区显示:

格式:

p<回车>

功能:

逐页地(每页20行)显示活区内容,每显示一页之后请用户决定是否继续显示以后备页(如果存在)。

印出的每一行要前置行号和一个空格符,行号固定占4位,增量为1。

(6)模式匹配:

格式:

k<回车><匹配文本><回车>

1.3设计进度

1》2012.8.20——2012.8.21需求分析

2》2012.8.21下午交需求分析,主要分析课题的内容,需要用的数据结构,小组分工情况

3》2012.8.22——2012.8.29编写源代码

4》2012.8.30完成设计并书写课程设计说明书

5》2012.8.31等待老师验收

1.4分工

薛建明:

进行插入功能的编写。

丛前:

进行删除功能的编写。

甘炀:

进行活区的切换功能的编写。

杨志文:

进行活区显示,KMP算法,界面的编写。

2.需求分析及总体设计

2.1数据结构

用到数据结构的双向链表:

typedefstructtext

{

charstring[80];

structtext*next;

structtext*pre;

intflat;

}text;

2.2功能框架

 

(1)行插入:

在指定行之后插入一行或几行。

(2)行删除:

在指定行之后插入一行或几行。

(3)行替换:

在指定行之后插入一行或几行。

(4)活区切换:

将活区写入输出文件,并从输入文件中读入下一段,作为新的活区。

(5)活区显示:

逐页地(每页20行)显示活区内容,每显示一页之后请用户决定是否继续显示以后备页(如果存在)。

印出的每一行要前置行号和一个空格符,行号固定占4位,增量为1。

(6)模式匹配:

在当前活区中查找所要匹配的文本。

3.功能模块详细设计

3.1设计流程

行插入功能:

找到要插入的结点对应的指针,然后开辟新的空间,把开辟出的新的空间,与刚才的结点连接,同时再把新节点的指针域只向出入的下一个节点。

主要思想:

p=(text*)malloc(sizeof(text));//p为新插入节点

p->next=p1->next;//p1为要出入结点的

p->pre=p1;

p1->next->pre=p;

p1->next=p;

 

3.2主要源代码

voidinsert()

{

inti,j,hang,increhang=1,incre;

chars;

text*p,*p1,*p2;

printf("(Note:

thei-throwinserttextinthei-throw!

!

Insertedtextin#Pleaseenterthelinenumberfortheendoftheflag):

\n");

scanf("%d",&hang);

p=p1=NULL;

if(hang==0)

{

p=(text*)malloc(sizeof(text));

p->flat=1;

p->next=head;

head->pre=p;

head=p;

}

if(hang!

=0)

{

for(i=0,p1=head;inext);//找到要插入行的前一行

p=(text*)malloc(sizeof(text));//为插入行分配空间

p->flat=1;

p->next=p1->next;

p->pre=p1;

p1->next->pre=p;

p1->next=p;

}//从此行将插入行插入到链表中

p->string[0]=getchar();

p->string[0]=getchar();

i=0;

incre=1;

while(p->string[i]!

='#')

{

if(incre==80)

{

s=getchar();

if(s=='#')

{

i++;

p->string[i]=s;

break;

}

p1=p;

p=(text*)malloc(sizeof(text));

p->flat=1;

p->next=p1->next;

p->pre=p1;

p1->next->pre=p;

p1->next=p;//从此行将插入行插入到链表中

i=0;

incre=1;

p->string[i]=s;

}

i++;

incre++;

p->string[i]=getchar();

}

p->string[i]='\n';

p->string[i+1]='\0';

puts("Modifiedtext:

\n");

head->flat=1;

for(p2=head,j=1;(j<=20)&&(p2!

=NULL);j++,p2=p2->next)//显示出修改后的链表

if(p2->flat==1)

printf("line%2d:

%s",j,p2->string);

if(feof(fp))

printf("Filehasended!

");

}

4.功能模块详细设计

4.1设计流程

行删除:

找到要删除的第一行和要删除的最后一行,分别把他们的指针域记录下来,把要删除的最后一行之后的文本往前移使的一页达到20行。

4.2主要源代码

voiddel()

{

text*p1,*p2,*p3,*p4;

inti,j;

xiugai=1;

printf("thefirstlineandthelastlineyouwanttodelete\n");

scanf("%d%d",&min,&max);

if(head==NULL)

printf("\nlistnull!

\n");

p1=p2=head;

if(min==1)

p1=head;

else

{

for(i=0;i

p1=p1->next;

}

p3=p1;

for(i=0;i

p2=p2->next;

p4=p2;

for(;p4!

=NULL;p3=p3->next)/*删除中间节点,将flat赋值0*/

{

strcpy(p3->string,p4->string);

p3->flat=p4->flat;

p4=p4->next;

}

for(;p3!

=NULL;p3=p3->next)

fgets(p3->string,sizeof(p3->string),fp);

printf("Modifiedtext:

\n");

for(i=0,j=0,p3=head;i<20;i++,p3=p3->next)

{

if(p3->flat==1)

printf("line%2d:

%s",j+1,p3->string);

j++;

}

}

5.功能模块详细设计

5.1设计流程

活区切换:

5.2主要源代码

voidsaveshow()

{

inti=0,j=0;

charconti='y';

text*p=NULL,*p1,*p2,*p3;

for(i=0,p=head;(p!

=NULL)&&(i<20);i++,p=p->next)

if(p->flat==1)

fputs(p->string,out);

p3=p1=head;

if(p==NULL)

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

{

p3->flat=1;

p3=p3->next;

}

if(p!

=NULL)

{for(i=0;(p!

=NULL)&&(i<20);i++,p=p->next)

if(p->flat==1)

{

strcpy(p1->string,p->string);

j=j+1;

p->flat=0;

p1=p1->next;

p1->flat=1;

}

}

if(j<20)

{

p2=p1;

for(;(j<20)&&(!

feof(fp));j++,p2=p2->next)//从文件读入活区

fgets(p2->string,sizeof(p2->string),fp);

if(j<20&&(feof(fp)))

{p2=p2->pre;

for(;p2!

=NULL;p2=p2->next)

p2->flat=0;

}

}

}

 

6.功能模块详细设计

6.1设计流程

模式匹配KMP算法,编辑函数,用来接受处理编辑命令,活区显示,行替换,活区显示,保存

6.2主要源代码

//活区显示

voidappear()

{

voidEXIT();

inti,j;

charconti='Y';

text*p2;

if(!

feof(fp))

{

page++;

printf("*******************************page%d*****************************************\n",page);

for(i=0,p2=head;i<20;i++,p2=p2->next)

{

if(p2->flat==1)

printf("line%2d:

%s",i+1,p2->string);

}

puts("Shouldcontinuetoreadintoit?

(Y/N):

");

conti=getchar();

conti=getchar();

if((conti=='y'||conti=='Y'))

{

saveshow();

appear();

}

}

else

{

page++;

printf("*******************************page%d*****************************************\n",page);

for(i=0,p2=head;i<20;i++,p2=p2->next)

{

if(p2->flat==1)

printf("line%2d:

%s",i+1,p2->string);

}

puts("\nFilehasended!

\n");

}

}

//****************退出编辑函数后执行的函数,将所有的内容存盘******************

voidsaveall()

{

inti;

text*p;

for(i=0,p=head;i<20;i++,p=p->next)//将活区写入文件

if(p->flat==1)

{

fputs(p->string,out);

p->flat=0;

}

while(!

feof(fp))//将其余的内容写入文件

fputc(fgetc(fp),out);

}

voidchange()

{

inti,j,hang,incre,inc;

chars;

text*p,*p1,*p2;

xiugai=1;

printf("Pleaseinputthelinenumberyouwanttoreplace(replacetextin#istheending):

\n");

scanf("%d",&hang);

p=p1=NULL;

if(hang==1)

p=head;

else

for(i=0,p=head;inext);

p->string[0]=getchar();

p->string[0]=getchar();

p->flat=1;

i=0;

incre=1;

while(p->string[i]!

='#')

{

i++;

incre++;

p->string[i]=getchar();

if(incre==80)

{

inc++;

p->string[i+1]='\n';

p->string[i+2]='\0';

s=getchar();

if(s=='#')

{

i++;

p->string[i]=s;

break;

}

p1=p;

p=(text*)malloc(sizeof(text));

p->flat=1;

p->next=p1->next;

p->pre=p1;

p1->next->pre=p;

p1->next=p;

i=0;

incre=1;

p->string[i]=s;

}

}

p->string[i]='\n';

p->string[i+1]='\0';

puts("Modifiedtext:

\n");

for(p2=head,j=1;(j<=20)&&(p2!

=NULL);j++,p2=p2->next)

{

if(p2->flat==1)

printf("line%2d:

%s",j,p2->string);

}

if(feof(fp))

printf("Filehasended!

");

}

//*************模式匹配KMP算法***************

voidKMP()

{

intm=1,next[80];

inti=0,j=-1;

text*p;

inta=0,b=0,F=0;

chars[80],t[80];

intlens,lent,k;

p=head;

printf("Pleaseenterthestringyouwanttopatternmatching:

\n");

scanf("%s",t);

lent=strlen(t);

do

{

lens=strlen(p->string);

strcpy(s,p->string);

next[0]=-1;

while(i

{

if(j==-1||t[i]==t[j])

{

++i;

++j;

next[i]=j;

}

elsej=next[j];

}

while(a

{

if(b==-1||s[a]==t[b])

{

++a;

++b;

}

else

b=next[b];

}

if(b>(lent-1))

{

k=a-lent+1;

printf("Youwanttomatchinthestring:

line%2dwords%d\n",m,k);

F=1;

}

i=0;

j=-1;

a=0;

b=0;

p=p->next;

m++;

}

while(m<=20);

if(F==0)

printf("Sorry!

Failedtofindthestringyouwanttomatchinthecurrenttext\n");

elseprintf("Matchisready!

!

\n");

}

voiddrawmain()/*画主窗口函数*/

{

inti,j;

gotoxy(1,1);/*在文本窗口中设置光标至(1,1)处*/

insline();/*在文本窗口的(1,1)位置处中插入一个空行*/

gotoxy(20,1);

cprintf("%c%cFile%c%c",179,17,16,179);/*|<>|*/

gotoxy(45,1);

cprintf("%c%cEdit%c%c",179,17,16,179);/*|<>|*/

gotoxy(5,25);/*跳至窗口底端*/

}

voiddrawmenu(intm,intn)/*画菜单,m:

第几项菜单,n:

第m项的第n个子菜单*/

{

inti;

if(m%2==0)/*画File菜单项*/

{

window(21,2,32,6);

textcolor(0);

textbackground(7);

for(i=0;i<4;i++)/*在上面定义的文本窗口中先输出5个空行*/

{

gotoxy(1,1+i);

insline();

}

window(1,1,80,25);

gotoxy(20,1);

for(i=1;i<=5;i++)

{

gotoxy(21,1+i);

cprintf("%c",179);/*窗口内文本的输出函数,在窗口左边输出|*/

gotoxy(32,1+i);

cprintf("%c",179);/*窗口内文本的输出函数,在窗口右边输出|*/

}

for(i=1;i<=11;i++)

{

gotoxy(21+i,2);

cprintf("%c",196);/*窗口内文本的输出函数,在窗口上边输出-*/

gotoxy(21+i,6);

cprintf("%c",196);/*窗口内文本的输出函数,在窗口下边输出-*/

}

/*以上为显示菜单项的外观*/

textbackground(7);

gotoxy(21,2);

cprintf("%c",218);/*输出四个边角表格符*/

gotoxy(21,6);

cprintf("%c",192);

gotoxy(32,2);

cprintf("%c",191);

gotoxy(32,6);

cprintf("%c",217);

gotoxy(22,3);

cprintf("Open");

gotoxy(22,4);

cprintf("Save");

gotoxy(22,5);

cprintf("Exit");

textcolor(15);

textbackground(0);

gotoxy(20,1);

cprintf("%c%cFile%c%c",179,17,16,179);

switch(n%3)

{

case0:

gotoxy(22,3);

cprintf("Open");

break;

case1:

gotoxy(22,4);

cprintf("Save");

break;

case2:

gotoxy(22,5);

cprintf("Exit");

break;

}

}

/********************************************************/

if(m%2==1)/*画Edit菜单项*/

{

window(46,2,57,8);

textcolor(0);

textbackground(7);

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

{

gotoxy(1,1+i);

insline();

}

window(1,1,80,25);

gotoxy(45,1);

for(i=1;i<=8;i++)

{

gotoxy(46,1+i);

cprintf("%c",179);

gotoxy(57,1+i);

cprintf("%c",179);

}

for(i=1;i<=11;i++)

{

gotoxy(46+i,2);

cprintf("%c",196);

gotoxy(46+i,9);

cprintf("%c",196);

}

textbackground(7);

gotoxy(46,2);

cprintf("%c",218);

gotoxy(46,9);

cprintf("%c",192);

gotoxy(57,2);

cprintf("%c",191);

gotoxy(57,9);

cprintf("%c",217);

gotoxy(47,3);

cprintf("del");

gotoxy(47,4);

cprintf("insert");

gotoxy(47,5);

cprintf("change");

gotoxy(47,6);

cprintf("KMP");

gotoxy(47,7);

cprintf("saveshow");

gotoxy(47,

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

当前位置:首页 > 高中教育 > 语文

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

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