欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    2022年文件系统模拟设计c++ 2.pdf

    • 资源ID:33369779       资源大小:60.86KB        全文页数:11页
    • 资源格式: PDF        下载积分:4.3金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要4.3金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    2022年文件系统模拟设计c++ 2.pdf

    #include stdio.h #include iostream.h #include string.h #include iomanip.h #define FILENAME_LENGTH 10 /文件名称长度#define COMMAND_LENGTH 10 /命令行长度#define PARA_LENGTH 30 /参数长度/账号结构typedef struct users char name8; char pwd10; users; /文件结构struct fnode char filenameFILENAME_LENGTH; int isdir; int isopen; char content255; /我是目录 /我是文件fnode *parent; fnode *child; fnode *prev; fnode *next; ; /账号users usrarray8 = usr1,usr1, usr2,usr2, usr3,usr3, usr4,usr4, usr5,usr5, usr6,usr6, usr7,usr7, usr8,usr8, ; fnode *initfile(char filename,int isdir); void createroot(); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 11 页 - - - - - - - - - int run(); int findpara(char *topara); bool chklogin(char *users, char *pwd); void help(); int mkdir(); int create(); int read(); int write(); int del(); int cd(); int dir(); fnode *root,*recent,*temp,*ttemp; char paraPARA_LENGTH,commandCOMMAND_LENGTH,tempparaPARA_LENGTH,recentparaPARA_LENGTH; /创建文件与目录结点fnode* initfile(char filename,int isdir) fnode *node=new fnode; strcpy(node-filename,filename); node-isdir=isdir; node-isopen=0; node-parent=NULL; node-child=NULL; node-prev=NULL; node-next=NULL; return node; /创建文件存储结点void createroot () recent=root=initfile(/,1); root-parent=NULL; root-child=NULL; root-prev=root-next=NULL; strcpy(para,/); int mkdir() temp=initfile( ,1); cintemp-filename; if(recent-child=NULL) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 11 页 - - - - - - - - - temp-parent=recent; temp-child=NULL; recent-child=temp; temp-prev=temp-next=NULL; else ttemp=recent-child; while(ttemp-next) ttemp=ttemp-next; if(strcmp(ttemp-filename,temp-filename)=0&ttemp-isdir=1) printf( 对不起 ,目录已存在 !); return 1; ttemp-next=temp; temp-parent=NULL; temp-child=NULL; temp-prev=ttemp; temp-next=NULL; return 1; int create() temp=initfile( ,0); cintemp-filename; cintemp-content; if(recent-child=NULL) temp-parent=recent; temp-child=NULL; recent-child=temp; temp-prev=temp-next=NULL; cout 文件建立成功!child; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 11 页 - - - - - - - - - while(ttemp-next) ttemp=ttemp-next; if(strcmp(ttemp-filename,temp-filename)=0&ttemp-isdir=0) printf( 对不起 ,文件已存在 !); return 1; ttemp-next=temp; temp-parent=NULL; temp-child=NULL; temp-prev=ttemp; temp-next=NULL; cout 文件建立成功!endl; return 1; int dir() int i=0,j=0; temp=new fnode; temp=recent; if(temp!=root) cout .child=NULL) coutTotal: directors i files j child; while(temp) if(temp-isdir) cout filenameendl;i+; else cout filenamenext; coutTotal: directors i files j filename; if(recent-child=NULL) cout 文件不存在 !child-filename,filename)=0) coutchild-contentchild; while(temp-next) if(strcmp(temp-next-filename,filename)=0) coutnext-contentendl; return 1; cout 文件不存在 !filename; if(recent-child=NULL) cout 文件不存在 !child-filename,filename)=0) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 11 页 - - - - - - - - - recent-child-isopen=1;/ 设置文件标记为打开cinrecent-child-content; recent-child-isopen=0;/ 设置文件标记为关闭cout 文件写入成功!child; while(temp-next) if(strcmp(temp-next-filename,filename)=0) recent-child-isopen=1;/ 设置文件标记为打开cintemp-next-content; recent-child-isopen=0;/ 设置文件标记为关闭cout 文件写入成功!endl; return 1; cout 文件不存在 !topara; if(strcmp(topara,.)=0) int i; while(recent-prev) recent=recent-prev; if(recent-parent) recent=recent-parent; i=strlen(para); while(parai!=/ & i0) i-; if(i!=0) parai=0; else parai+1=0; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 11 页 - - - - - - - - - else findpara(topara); return 1; int findpara(char *topara) int i=0; int sign=1; if(strcmp(topara,/)=0) recent=root; strcpy(para,/); return 1; temp=recent; strcpy(temppara,para); if(topara0=/) recent=root-child; i+; strcpy(para,/); else if(recent!=NULL & recent!=root) strcat(para,/); if(recent & recent-child) if(recent-isdir) recent=recent-child; else printf( 路径错误! n); return 1; while(ichild) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 11 页 - - - - - - - - - i+; if(recent-isdir) recent=recent-child; else printf( 路径错误 n); return 0; strcat(para,/); while(toparai!=/ & ifilename,recentpara)!=0 | (recent-isdir!=1) & recent-next!=NULL) recent=recent-next; if(strcmp(recent-filename,recentpara)=0) if(recent-isdir=0) strcpy(para,temppara); recent=temp; printf( 是文件不是目录。n); return 0; strcat(para,recent-filename); if(strcmp(recent-filename,recentpara)!=0 | recent=NULL) strcpy(para,temppara); recent=temp; printf( 输入路径错误 n); return 0; return 1; int del() char filenameFILENAME_LENGTH; cinfilename; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 11 页 - - - - - - - - - temp=new fnode; if(recent-child) temp=recent-child; while(temp-next & (strcmp(temp-filename,filename)!=0 | temp-isdir!=0) temp=temp-next; if(strcmp(temp-filename,filename)!=0) cout 不存在该文件!endl; return 0; else cout 不存在该文件!parent=NULL) temp-prev-next=temp-next; if(temp-next) temp-next-prev=temp-prev; temp-prev=temp-next=NULL; else if(temp-next) temp-next-parent=temp-parent; temp-parent-child=temp-next; delete temp; cout 文件已删除 !endl; bool chklogin(char *users, char *pwd) int i; for(i=0; i8; i+) if( (strcmp(users,usrarrayi.name)=0) & (strcmp(pwd,usrarrayi.pwd)=0) return true; return false; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 11 页 - - - - - - - - - void help(void) cout 命令一览endl; coutendl; coutcreate: 建立文件。endl; coutread: 读取文件。endl; coutwrite: 写入文件 ,支持多线程endl; coutdel : 删除文件。endl; coutmkdir: 建立目录。endl; coutcd: 切换目录。endl; coutlogout: 退出登录。endl; int run() coutlinux:para; cincommand; if(strcmp(command,mkdir)=0) mkdir(); else if(strcmp(command,dir)=0) dir(); else if(strcmp(command,cd)=0) cd(); else if(strcmp(command,create)=0) create(); else if(strcmp(command,read)=0) read(); else if(strcmp(command,write)=0) write(); else if(strcmp(command,del)=0) del(); else if(strcmp(command,help)=0) help(); else if(strcmp(command,logout)=0) return 0; else cout 请参考 help 提供的命令列表!endl; int main() int i=0; bool in=false; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 11 页 - - - - - - - - - char users8,pwd12; cout|-|endl; cout| c语 言 模 拟Linux文 件 系 统|endl; cout| 账号: usr1-usr8 密码: usr1-usr8 |endl; cout| 你 只 有 三 次 机 会 来 试 验 账 号|endl; cout| 键入 help 可以获取帮助|endl; cout|_|endl; coutendl; while(i3) coutusers; coutpwd; if(chklogin(users,pwd) in=true;break; i+; createroot(); printf(root dir create okn); while(in) if(!run() break; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 11 页,共 11 页 - - - - - - - - -

    注意事项

    本文(2022年文件系统模拟设计c++ 2.pdf)为本站会员(H****o)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开