堆栈应用题Word文档格式.docx

上传人:b****4 文档编号:6498618 上传时间:2023-05-06 格式:DOCX 页数:27 大小:1.97MB
下载 相关 举报
堆栈应用题Word文档格式.docx_第1页
第1页 / 共27页
堆栈应用题Word文档格式.docx_第2页
第2页 / 共27页
堆栈应用题Word文档格式.docx_第3页
第3页 / 共27页
堆栈应用题Word文档格式.docx_第4页
第4页 / 共27页
堆栈应用题Word文档格式.docx_第5页
第5页 / 共27页
堆栈应用题Word文档格式.docx_第6页
第6页 / 共27页
堆栈应用题Word文档格式.docx_第7页
第7页 / 共27页
堆栈应用题Word文档格式.docx_第8页
第8页 / 共27页
堆栈应用题Word文档格式.docx_第9页
第9页 / 共27页
堆栈应用题Word文档格式.docx_第10页
第10页 / 共27页
堆栈应用题Word文档格式.docx_第11页
第11页 / 共27页
堆栈应用题Word文档格式.docx_第12页
第12页 / 共27页
堆栈应用题Word文档格式.docx_第13页
第13页 / 共27页
堆栈应用题Word文档格式.docx_第14页
第14页 / 共27页
堆栈应用题Word文档格式.docx_第15页
第15页 / 共27页
堆栈应用题Word文档格式.docx_第16页
第16页 / 共27页
堆栈应用题Word文档格式.docx_第17页
第17页 / 共27页
堆栈应用题Word文档格式.docx_第18页
第18页 / 共27页
堆栈应用题Word文档格式.docx_第19页
第19页 / 共27页
堆栈应用题Word文档格式.docx_第20页
第20页 / 共27页
亲,该文档总共27页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

堆栈应用题Word文档格式.docx

《堆栈应用题Word文档格式.docx》由会员分享,可在线阅读,更多相关《堆栈应用题Word文档格式.docx(27页珍藏版)》请在冰点文库上搜索。

堆栈应用题Word文档格式.docx

boolsearch(charfileroad[],charfilename[]);

//寻找指定元素

类外的函数

函数名称

返回类型

所含参数

实现功能

in_word()

int

charfileroad[]

charfilename[]

对文件进行输入编辑

copy_word()

charfileorignl[]

charfileroad[]

对文件中的内容进行拷贝

creatfile()

void

filestack&

fstack1

fstack3

fstack4

创建新文件并备份

deletefile()

fstack

删除文件操作

recoverfile()

fstack,

恢复删除的文件

recoverfileroad()

charofileroad[]

复制文件路径

undo_moreoperate()

fstack1

fstack2

fstack3

fstack4

char&

op

charfroado[]

撤销之前的某步操作

undo_operate()

撤消操作

searchroad()

寻找文件路径

redo_file()

重做操作

delete_copyoperate()

删除副本(及删除“copy”文件夹里的文件)

save()

对所有操作进行保存,不可恢复

f_operate()

对文件进行操作

(三)用户手册

程序运行时,首先提示选择要进行的操作。

对于创建文件时,提示输入文件路径以及文件名

对于撤消操作时,提示进行撤销上一步还是撤销之前的操作;

对于重做操作,提示进行恢复的路径;

对于结束所有操作,提示是否保存所有操作。

(四)调试及测试

运行实例:

(1)创建文件的操作

(2)撤销操作

(3)重做操作

(4)保存所有操作

进一步改进

(1)目前程序中,主要以建立文件,删除文件以及恢复文件为主要功能,辅以对文件进行编辑。

以后可以加入打开文件等其他功能。

(2)目前是通过控制台进行操作,并不是很直观,在以后可以借助图形界面(MFC)来实现对文件的操作。

附录源程序

(1)f_stack.h

#include<

iostream>

string>

fstream>

usingnamespacestd;

enumerror_code{success,underflow};

structnode{

charfroad[50];

//存储文件路径

charfname[30];

//存储文件名

node*next;

};

classfilestack{

public:

boolsearch(charfileroad[],charfilename[]);

private:

intcount;

node*top;

filestack:

:

filestack(){

count=0;

top=NULL;

}

boolfilestack:

empty()const{

returncount==0;

error_codefilestack:

get_top(charfileroad[],charfilename[])const{

if(empty()){

returnunderflow;

}

else{

strcpy(fileroad,top->

froad);

strcpy(filename,top->

fname);

returnsuccess;

push(charfileroad[],charfilename[]){

node*s=newnode;

strcpy(s->

froad,fileroad);

fname,filename);

s->

next=NULL;

next=top;

top=s;

count++;

returnsuccess;

pop(){

node*u=top;

top=top->

next;

deleteu;

count--;

pop(charfileroad[],charfilename[])

{

charcroad[80];

strcpy(croad,fileroad);

strcat(croad,filename);

filestackf1;

else{

charfr[50],frc[50],fn[30];

get_top(fr,fn);

strcpy(frc,fr);

if(strcmp(strcat(frc,fn),croad)==0){

pop();

}

else{

while(strcmp(strcat(frc,fn),croad)!

=0){

f1.push(fr,fn);

get_top(fr,fn);

strcpy(frc,fr);

}

while(!

f1.empty()){

f1.get_top(fr,fn);

push(fr,fn);

f1.pop();

//寻找指定文件

search(charfileroad[],charfilename[])

returnfalse;

returntrue;

returnfalse;

//析构函数

//对文件进行文字编辑

intin_word(charfileroad[],charfilename[])

charc='

A'

;

charfrc[50];

strcpy(frc,fileroad);

//拷贝文件路径

charfname[80];

strcpy(fname,strcat(frc,filename));

ofstreamoutfile(fname,ios:

out|ios:

trunc);

//打开相应文件

if(!

outfile){

cerr<

<

"

openerror!

endl;

exit

(1);

cout<

enterthewords:

//进行文字的录入

while(c!

='

\\'

){

cin>

>

c;

outfile<

outfile.close();

return0;

//对文件中的内容进行拷贝

intcopy_word(charfileorignl[],charfilename[],charfileroad[])

//创建新文件并备份

voidcreatfile(charfileroad[],charfilename[],filestack&

fstack1,filestack&

fstack3,filestack&

fstack4){

//指定备份路径

charfr[80]="

copy/"

charfrc[80]="

charfrs[80]="

redosave/"

charfrsc1[80]="

charfrsc2[80]="

charfrsr[80]="

redosaveroad/"

charfrscr1[80]="

charfrscr2[80]="

//创建文件

ofstreamoutfile1(strcat(croad,filename),ios:

outfile1){

}

outfile1.close();

//备份到指定路径

ofstreamoutfile2(strcat(fr,filename),ios:

outfile2){

copyerror!

outfile2.close();

//对所有创建操作建立映像

ofstreamoutfile3(strcat(frs,filename),ios:

outfile3){

savecopyerror!

outfile3.close();

//对创建文件的路径进行保存

ofstreamoutfile4(strcat(frsr,filename),ios:

outfile4){

charc[50];

inti=0;

while(fileroad[i]!

\0'

c[i]=fileroad[i];

i++;

c[i]='

i=0;

while(c[i]!

outfile4<

c[i];

outfile4.close();

————成功建立(更新)"

fileroad<

filename<

文件并备份成功————\n"

//对已创建的文件进行编辑

charchoice;

fstack1.push(fileroad,filename);

fstack3.push(frsc2,filename);

fstack4.push(frscr2,filename);

是否需要对新创建的文件进行编辑?

\n需要,键入Y;

不需要,键入N。

\n"

请确认是否需要进行编辑:

do{

cin>

choice;

switch(choice){

case'

N'

cout<

请选择下一步操作。

break;

Y'

in_word(fileroad,filename);

copy_word(croad,filename,frc);

copy_word(croad,filename,frsc1);

结束编辑,请选择下一步操作。

default:

输入错误!

请确认!

}}while(choice!

&

choice!

);

//删除文件操作

//恢复删除的文件

voidrecoverfile(filestack&

fstack,charfileroad[],charfilename[])

fstack.push(fileroad,filename);

charor[80]="

strcat(or,filename);

redoerror!

}copy_word(or,filename,fileroad);

//复制文件路径

voidrecoverfileroad(filestack&

fstack,charofileroad[],charfileroad[],charfilename[])

charfrsr[80];

strcpy(frsr,fileroad);

ofstreamoutfile(strcat(frsr,filename),ios:

while(ofileroad[i]!

c[i]=ofileroad[i];

//撤销之前的某步操作

voidundo_moreoperate(filestack&

fstack2,filestack&

fstack4,char&

op,charfroado[])

charchoice='

C'

charfileroad[50];

charfilename[30];

charofile[50]="

charsfile[50]="

charsrfile[50]="

请确认是恢复之前的删除(C),还是撤销之前的创建(U),请键入:

U'

请输入要撤销之前创建的文件路径:

cin>

fileroad;

strcpy(froado,fileroad);

请输入要撤销之前创建的文件名:

filename;

deletefile(fstack1,fileroad,filename);

deletefile(fstack3,sfile,filename);

deletefile(fstack4,srfile,filename);

fstack2.push(ofile,filename);

op='

请输入要恢复之前删除的文件路径:

请输入要恢复之前删除的文件名:

recoverfile(fstack1,fileroad,filename);

已成功恢复文件"

recoverfile(fstack3,sfile,filename);

recoverfileroad(fstack4,fileroad,srfile,filename);

fstack2.pop(ofile,filename);

请确认输入编号是否正确"

}while(choice!

//撤消操作

voidundo_operate(filestack&

O'

请确认撤消操作!

撤销上一步键入O,其它请键入M\n"

请输入:

"

if(op=='

fstack1.get_top(fileroad,filename);

strcpy(froado,fileroad);

deletefile(fstack1,fileroad,filename);

deletefile(fstack3,sfile,filename);

deletefile(fstack4,srfile,filename);

fstack2.push(ofile,filename);

cout<

成功删除文件"

;

op='

else{

fstack2.get_top(fileroad,filename);

recoverfile(fstack1,froado,filename);

recoverfile(fstack3,sfile,filename);

recoverfileroad(fstack4,froado,srfile,filename);

fstack2.pop();

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

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2