数据结构论文.docx

上传人:b****1 文档编号:19196388 上传时间:2023-04-24 格式:DOCX 页数:24 大小:411.38KB
下载 相关 举报
数据结构论文.docx_第1页
第1页 / 共24页
数据结构论文.docx_第2页
第2页 / 共24页
数据结构论文.docx_第3页
第3页 / 共24页
数据结构论文.docx_第4页
第4页 / 共24页
数据结构论文.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

数据结构论文.docx

《数据结构论文.docx》由会员分享,可在线阅读,更多相关《数据结构论文.docx(24页珍藏版)》请在冰豆网上搜索。

数据结构论文.docx

数据结构论文

目录

一、需求分析············································2

(一)、开发背景·········································2

(二)、项目目标·········································2

(三)、运行环境·········································2

(四)、项目任务书·······································2

二、技术路线············································2

(一)、总体路线·········································2

(二)、详细设计·········································3

方案一、C语言设计部分··································3

方案二、VC++设计部分···································8

三、工程进度···········································22

四、测试分析···········································23

五、个人总结···········································23

六、用户手册···········································24

七、参考文献···········································24

 

1、需求分析

(一)、开发背景

随着计算机技术的发展,人们的生活也越来越简单化,比如人们不需要再去手写大量的稿件,只需用计算机打字输入,打印。

为了更方便人们对文档修改的操作,我们运用数据结构的知识和mfc编程提供的函数,编写合理的查找和替换算法,用以实现对文本中有的字符,查找出来并替换掉的操作。

(二)、项目目标

本项目主要实现以下功能

打开一篇英文文章,在该文章中找出所有给定的单词

对所有给定的单词替换为另外一个单词,再存盘。

(三)、运行环境

硬件环境:

处理器Intel(R)Core(TM)2DuoCPUT6400@2.00GHz2.00GHz

内存(RAM):

2.00GB

系统类型:

32位操作系统

软件环境:

WindowsXP

VisualC++6.0

(四)、项目任务书

本程序我们分别用C语言和VC++设计了两个程序,由两人合作完成,其中韩丽霞为总负责,承担字符串查找与替换的总体规划与模块功能的设计,其中代码部分也主要由她完成,赵永恒则负责文档的撰写,以及查找用VC++设计窗体化的资料。

2、技术路线

(一)、总体方案

 

(二)、详细设计

方案一、C语言设计方案部分

所用函数介绍

1、程序预编译函数(即头文件)简析

1、#include

程序所需要的输入和输出操作的有关信息

2、#include

程序中字符串函数的有关信息

3、#include

程序中动态存储分配函数的有关信息

2、程序中相关函数的解析

输入流成员函数用于从磁盘文件中输入,这些成员函数包括:

Open函数get函数

Getline函数read函数

Seekg函数和tellg函数close函数

我们的程序中用到的getline函数功能:

是允许从输入流中读取多个字符,并且允许指定输入终止字符(默认值是换行字符),

在读取完成后,从读取的内容中删除该终止字符。

例:

Cin.getline(s,1000,'\n');

功能:

字符类型数组S从键盘连续读入一串字符,直到遇到回车符"\n"时停止,字符个数最多不超过1000个

3、程序所涉及知识点

1.头文件

2.输入输出函数

3.字符串操作函数

4.数组操作

5.辅助指针变量

四、程序流程图

五、程序代码如下:

#include

#include

#include

voidchange(char*ptrm,chart[],char*ptr_str)

{

intk=0,i,j,len;

char*ptrs=t;

len=strlen(t);

while(*ptrm!

='\0')//外层循环,移动母串指针

{

i=0;

k=0;

while(*(ptrs+i)!

='\0')//内层循环,匹配字符串

{

if(*(ptrs+i)==*(ptrm+k))//如果该位匹配,后移一位,继续匹配下一位

{i++;k++;}

elsebreak;

}

//if(*(ptrs+i)=='\0')说明上面的内层循环已经匹配玩字字符串的最后一位

if(*(ptrs+i)=='\0')//当已经匹配了字符串,母串指针后移len单元,减少尝试次数,优化算法,然后将所匹配的字符串替换掉

{

for(j=0;j

{

*(ptrm+j)=*(ptr_str+j);

}

for(j=0;j

}

elseptrm++;//如果匹配不成功,那么母串指针后移一个单元,继续匹配

}

}

voidmain()

{

chars[100],t[100],t1[100];

cout<<"请输入文本一:

"<

cin.getline(s,100,'\n');

cout<<"请输入查找的字符串:

"<

cin.getline(t,100,'\n');

cout<<"请输入替换的字符串:

"<

cin.getline(t1,100,'\n');

change(s,t,t1);

cout<<"替换后的新文本为:

"<

system("pause");

}

六、运行结果

运行后界面如图,输入如图所示字符串

我们将其中的like替换成love操作如下

由图所示替换成功。

方案二、用VC++设计部分

一、界面设计

我们采用了当前最流行的VC++6.0作为开发工具,运行平台是WINDOW2000/XP。

通过C++提供的MFC类库,来设计更为简洁直观的对话框来实现字符串的查找与替换

操作界面流程图

点击运行查找替换字符串的可执行文件

在原始字符串中输入一段英语文章

在查找的字符串中输入要查找的字符串如图

点击查找按钮

如图所示会显示字符串的位置

在替换字符串文本栏输入要替换的字符串如图

点击替换按钮后如图所示

点击确定后文本框显示如下图所示

成功完成查找替换的操作

二、各个部分程序代码:

第一部分:

//SearchReplaceStr.cpp:

Definestheclassbehaviorsfortheapplication.

//

#include"stdafx.h"

#include"SearchReplaceStr.h"

#include"SearchReplaceStrDlg.h"

#ifdef_DEBUG

#definenewDEBUG_NEW

#undefTHIS_FILE

staticcharTHIS_FILE[]=__FILE__;

#endif

/////////////////////////////////////////////////////////////////////////////

//CSearchReplaceStrApp

BEGIN_MESSAGE_MAP(CSearchReplaceStrApp,CWinApp)

//{{AFX_MSG_MAP(CSearchReplaceStrApp)

//NOTE-theClassWizardwilladdandremovemappingmacroshere.

//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!

//}}AFX_MSG

ON_COMMAND(ID_HELP,CWinApp:

:

OnHelp)

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

//CSearchReplaceStrAppconstruction

CSearchReplaceStrApp:

:

CSearchReplaceStrApp()

{

//TODO:

addconstructioncodehere,

//PlaceallsignificantinitializationinInitInstance

}

/////////////////////////////////////////////////////////////////////////////

//TheoneandonlyCSearchReplaceStrAppobject

CSearchReplaceStrApptheApp;

/////////////////////////////////////////////////////////////////////////////

//CSearchReplaceStrAppinitialization

BOOLCSearchReplaceStrApp:

:

InitInstance()

{

AfxEnableControlContainer();

//Standardinitialization

//Ifyouarenotusingthesefeaturesandwishtoreducethesize

//ofyourfinalexecutable,youshouldremovefromthefollowing

//thespecificinitializationroutinesyoudonotneed.

#ifdef_AFXDLL

Enable3dControls();//CallthiswhenusingMFCinasharedDLL

#else

Enable3dControlsStatic();//CallthiswhenlinkingtoMFCstatically

#endif

CSearchReplaceStrDlgdlg;

m_pMainWnd=&dlg;

intnResponse=dlg.DoModal();

if(nResponse==IDOK)

{

//TODO:

Placecodeheretohandlewhenthedialogis

//dismissedwithOK

}

elseif(nResponse==IDCANCEL)

{

//TODO:

Placecodeheretohandlewhenthedialogis

//dismissedwithCancel

}

//Sincethedialoghasbeenclosed,returnFALSEsothatweexitthe

//application,ratherthanstarttheapplication'smessagepump.

returnFALSE;

}

第二部分:

//SearchReplaceStrDlg.cpp:

implementationfile

//

#include"stdafx.h"

#include"SearchReplaceStr.h"

#include"SearchReplaceStrDlg.h"

#ifdef_DEBUG

#definenewDEBUG_NEW

#undefTHIS_FILE

staticcharTHIS_FILE[]=__FILE__;

#endif

/////////////////////////////////////////////////////////////////////////////

//CAboutDlgdialogusedforAppAbout

classCAboutDlg:

publicCDialog

{

public:

CAboutDlg();

//DialogData

//{{AFX_DATA(CAboutDlg)

enum{IDD=IDD_ABOUTBOX};

//}}AFX_DATA

//ClassWizardgeneratedvirtualfunctionoverrides

//{{AFX_VIRTUAL(CAboutDlg)

protected:

virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport

//}}AFX_VIRTUAL

//Implementation

protected:

//{{AFX_MSG(CAboutDlg)

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

CAboutDlg:

:

CAboutDlg():

CDialog(CAboutDlg:

:

IDD)

{

//{{AFX_DATA_INIT(CAboutDlg)

//}}AFX_DATA_INIT

}

voidCAboutDlg:

:

DoDataExchange(CDataExchange*pDX)

{

CDialog:

:

DoDataExchange(pDX);

//{{AFX_DATA_MAP(CAboutDlg)

//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)

//{{AFX_MSG_MAP(CAboutDlg)

//Nomessagehandlers

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

//CSearchReplaceStrDlgdialog

CSearchReplaceStrDlg:

:

CSearchReplaceStrDlg(CWnd*pParent/*=NULL*/)

:

CDialog(CSearchReplaceStrDlg:

:

IDD,pParent)

{

//{{AFX_DATA_INIT(CSearchReplaceStrDlg)

m_strData=_T("");

m_strFind=_T("");

m_strReplace=_T("");

//}}AFX_DATA_INIT

//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32

m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

voidCSearchReplaceStrDlg:

:

DoDataExchange(CDataExchange*pDX)

{

CDialog:

:

DoDataExchange(pDX);

//{{AFX_DATA_MAP(CSearchReplaceStrDlg)

DDX_Text(pDX,IDC_EDIT1,m_strData);

DDX_Text(pDX,IDC_EDIT2,m_strFind);

DDX_Text(pDX,IDC_EDIT3,m_strReplace);

//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CSearchReplaceStrDlg,CDialog)

//{{AFX_MSG_MAP(CSearchReplaceStrDlg)

ON_WM_SYSCOMMAND()

ON_WM_PAINT()

ON_WM_QUERYDRAGICON()

ON_BN_CLICKED(IDC_REPLACE,OnReplace)

ON_BN_CLICKED(IDC_SEARCH,OnSearch)

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

//CSearchReplaceStrDlgmessagehandlers

BOOLCSearchReplaceStrDlg:

:

OnInitDialog()

{

CDialog:

:

OnInitDialog();

//Add"About..."menuitemtosystemmenu.

//IDM_ABOUTBOXmustbeinthesystemcommandrange.

ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX);

ASSERT(IDM_ABOUTBOX<0xF000);

CMenu*pSysMenu=GetSystemMenu(FALSE);

if(pSysMenu!

=NULL)

{

CStringstrAboutMenu;

strAboutMenu.LoadString(IDS_ABOUTBOX);

if(!

strAboutMenu.IsEmpty())

{

pSysMenu->AppendMenu(MF_SEPARATOR);

pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);

}

}

//Settheiconforthisdialog.Theframeworkdoesthisautomatically

//whentheapplication'smainwindowisnotadialog

SetIcon(m_hIcon,TRUE);//Setbigicon

SetIcon(m_hIcon,FALSE);//Setsmallicon

//TODO:

Addextrainitializationhere

returnTRUE;//returnTRUEunlessyousetthefocustoacontrol

}

voidCSearchReplaceStrDlg:

:

OnSysCommand(UINTnID,LPARAMlParam)

{

if((nID&0xFFF0)==IDM_ABOUTBOX)

{

CAboutDlgdlgAbout;

dlgAbout.DoModal();

}

else

{

CDialog:

:

OnSysCommand(nID,lParam);

}

}

//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow

//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,

//thisisautomaticallydoneforyoubytheframework.

voidCSearchReplaceStrDlg:

:

OnPaint()

{

if(IsIconic())

{

CPaintDCdc(this);//devicecontextforpainting

SendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);

//Centericoninclientrectangle

intcxIcon=GetSystemMetrics(SM_CXICON);

intcyIcon=GetSystemMetrics(SM_CYICON);

CRectrect;

GetClientRect(&rect);

intx=(rect.Width()-cxIcon+1)/2;

inty=(rect.Height()-cyIcon+1)/2;

//Drawtheicon

dc.DrawIcon(x,y,m_hIcon);

}

else

{

CDialog:

:

OnPaint();

}

}

//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags

//theminimizedwindow.

HCURSORCSearchReplaceStrDlg:

:

OnQueryDragIcon()

{

return(HCURSOR)m_hIcon;

}

voidCSearchReplaceStrDlg:

:

OnReplace()

{

//TODO:

Addyourcontrolnotificationhandlercodehere

程序源代码

UpdateData(true);

if(m_strFind.IsEmpty())

{

AfxMessageBox("查找的字符串为空!

");//判断编辑框字符串是否为空

return;

}

intnum;

num=m_strData.Replace(m_strFind,m_strReplace);//替换字符串

CStringstr;

str.Format("共完成了%d处替换",num);

AfxMessageB

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

当前位置:首页 > 医药卫生 > 预防医学

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

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