




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、【實驗報告正文】一、實驗?zāi)康暮鸵螅ū靥睿嶒災(zāi)康模和ㄟ^在VC平臺下編程,設(shè)計和調(diào)試一個簡單的文件系統(tǒng),通過模擬文件操作命令的執(zhí)行,來模擬文件系統(tǒng)對文件及目錄的管理。實驗要求:兩名學(xué)生成組結(jié)對完成實驗,仿真出文件系統(tǒng)中對文件和目錄的操作。二、實驗容(必填)文件管理:實現(xiàn)一個簡單的文件系統(tǒng)文三、實驗原理或?qū)嶒灧椒ǎū靥睿┒≡恚和ㄟ^結(jié)構(gòu)體來描述文件和目錄,利用鏈表知識實現(xiàn)目錄樹結(jié)構(gòu),通過對鏈表的操作實戔現(xiàn)整個文件系統(tǒng)中目錄和文件的相關(guān)操作。:方法:學(xué)生兩人結(jié)對進(jìn)行實驗,分別實現(xiàn)對文件和目錄的操作。:對文件的操作包括:創(chuàng)建文件create、讀文件read、寫文件write、刪除文件delete:對
2、目錄的操作包括:創(chuàng)建目錄mkdir、切換目錄cd、展示目錄容dir、刪除目錄rm。:四、主要儀器設(shè)備或?qū)嶒灄l件-:Windows操作系統(tǒng),VC開發(fā)環(huán)境F-r:五、實驗步驟(含實驗數(shù)據(jù)記錄處理)或操作設(shè)計過程記錄#include"stdio.h"br#include"iostream.h"#include"string.h"r:#defineFILENAMELENGTH10/文件名稱長度f-#defineCOMMAND_LENGTH10/命令行長度E#definePATHLENGTH30/參數(shù)長度structfilenodecharfi
3、lenameFILENAME_LENGTH;intisdir;charcontent255;filenode*parent;filenode*child;filenode*prev;filenode*next;filenode*initnode(charfilename口,intisdir);voidcreateroot();intrun();intfindpath(char*topath);voidhelp();intmkdir();intcreate();intread();intwrite();intdel();intrm();intcd();intdir();filenode*root
4、,*recent,*temp,*ttemp,*temp_child;charpathPATH_LENGTH,commandCOMMAND_LENGTH,temppathPATH_LENGTH,recentpathPATH_LENGTH;創(chuàng)建文件或目錄的存儲節(jié)點filenode*initnode(charfilename口,intisdir)filenode*node=newfilenode;strcpy(node->filename,filename);node->isdir=isdir;node->parent=NULL;node->child=NULL;node-&
5、gt;prev=NULL;node->next=NULL;returnnode;/初始化文件系統(tǒng)根結(jié)點voidcreateroot()recent=root=initnode("/”,1);root->parent=NULL;root->child=NULL;root->prev=root->next=NULL;strcpy(path,"/");zvoidhelp()cout<<endl;cout<<"create:cout<<"read:cout<<"wr
6、ite:cout<<"delete:cout<<"rm:cout<<"mkdir:建立文件讀取文件寫入文件。刪除文件,刪除目錄.建立目錄C"<<endl;"<<endl;"<<endl;"<<endl;"<<endl;"<<endl;切換目錄"<<endl;"<<endl;"<<endl;cout<<"cd:co
7、ut<<"dir:顯示目錄。cout<<"logout:退出登錄。)intdir()(inti=0,j=0;temp=newfilenode;<<"."<<endl; <<,1"<<endl;i+;files "<< j <<endl;temp=recent;if(temp=root)cout<<"<DIR>if(temp!=root)cout<<"<DIR>if(temp
8、->child=NULL)cout<<"Total:"<<"directors"<<i<<return1;)temp=temp->child;while(temp)if(temp->isdir)"<<temp->filename<<endl;i+;"<<temp->filename<<endl;j+;files"<< j <<endl;cout<<"<
9、;DIR>elsecout<<"<FILE>temp=temp->next;)cout<<"Total:"<<"directors"<<i<<"return0;)intread()charfilenameFILENAME_LENGTH;cin>>filename;if(recent->child=NULL)cout<<”文件不存在!"<<endl;return1;if(strcmp(recent-&g
10、t;child->filename,filename)=0)cout<<recent->child->content<<endl;return0;elsetemp=recent->child;while(temp->next)if(strcmp(temp->next->filename,filename)=0)cout<<temp->next->content<<endl;return0;cout<<”文件不存在!"<<endl;return1;intwrit
11、e()charfilenameFILENAME_LENGTH;cin>>filename;if(recent->child=NULL)cout<<”文件不存在!"<<endl;return1;if(strcmp(recent->child->filename,filename)=0)cin>>recent->child->content;cout<<”文件寫入成功!"<<endl;return0;elsetemp=recent->child;while(temp-&g
12、t;next)if(strcmp(temp->next->filename,filename)=0)cin>>temp->next->content;cout<<”文件寫入成功!"<<endl;return0;cout<<”文件不存在!"<<endl;return1;intdel()charfilenameFILENAME_LENGTH;cin>>filename;temp=newfilenode;if(recent->child)temp=recent->child
13、;while(temp->next&&(strcmp(temp->filename,filename)!=0|temp->isdir!=0)temp=temp->next;if(strcmp(temp->filename,filename)!=0|temp->isdir!=0)cout<<"不存在該文件!"<<endl;return0;elsecout<<"不存在該文件!"<<endl;return0;if(temp->parent=NULL)tem
14、p->prev->next=temp->next;if(temp->next)temp->next->prev=temp->prev;temp->prev=temp->next=NULL;elseif(temp->next)temp->next->parent=temp->parent;temp->parent->child=temp->next;deletetemp;cout<<”文件已刪除!"<<endl;return0;intrm()charfilenameF
15、ILENAME_LENGTH;cin>>filename;temp=newfilenode;if(recent->child)temp=recent->child;|while(temp->next&&(strcmp(temp->filename,filename)!=0temp->isdir!=1)temp=temp->next;if(strcmp(temp->filename,filename)!=0|temp->isdir!=1)cout<<”不存在該目錄!"<<endl;ret
16、urn0;elsecout<<”不存在該目錄!"<<endl;return0;if(temp->parent=NULL)temp->prev->next=temp->next;if(temp->next)temp->next->prev=temp->prev;temp->prev=temp->next=NULL;elseif(temp->next)temp->next->parent=temp->parent;temp->parent->child=temp->
17、;next;deletetemp;cout<<"目錄已刪除!"<<endl;return0;intcd()chartopathPATH_LENGTH;cin>>topath;if(strcmp(topath,".")=0)return0;if(strcmp(topath,".")=0)inti;while(recent->prev)recent=recent->prev;/向前回溯,找到第一次創(chuàng)建的目錄if(recent->parent)recent=recent->pare
18、nt;i=strlen(path);/printf("%d%sn",i,path);while(pathi!='/'&&i>0)i-;/找到最右邊的/if(i!=0)pathi='0'/printf("%s",path);/path中不止有一個/elsepathi+1='0'elsefindpath(topath);return0;intfindpath(char*topath)unsignedinti=0;intsign=1;if(strcmp(topath,"/"
19、;)=0)/如果命令是cd/recent=root;strcpy(path,"/");return0;temp=recent;strcpy(temppath,path);if(topath0='/')/cd命令以cd/開始recent=root->child;i+;strcpy(path,"/");/printf("n%s",path);elseif(recent!=NULL&&recent!=root)strcat(path,"/");/printf("n%sn&q
20、uot;,path);if(recent&&recent->child)if(recent->isdir)recent=recent->child;elseprintf("路徑錯誤!n");return1;while(i<=strlen(topath)&&recent)intj=0;if(topathi='/'&&recent->child)i+;if(recent->isdir)recent=recent->child;elseprintf("路徑錯誤n&q
21、uot;);return1;strcat(path,"/");while(topathi!='/'&&i<=strlen(topath)recentpathj=topathi;i+;j+;recentpathj='0'&&while(strcmp(recent->filename,recentpath)!=0|(recent->isdir!=1)recent->next!=NULL)recent=recent->next;if(strcmp(recent->filename,
22、recentpath)=0)if(recent->isdir=0)strcpy(path,temppath);recent=temp;printf("是文件不是目錄。n");return1;strcat(path,recent->filename);if(strcmp(recent->filename,recentpath)!=0|recent=NULL)strcpy(path,temppath);recent=temp;printf("輸入路徑錯誤n");return1;return0;intmkdir()temp=initnode(
23、"",1);cin>>temp->filename;if(recent->child=NULL)temp->parent=recent;temp->child=NULL;recent->child=temp;temp->prev=temp->next=NULL;printf("目錄建立成功!n");elsettemp=recent->child;if(strcmp(ttemp->filename,temp->filename)=0&&ttemp->isdir=1
24、)printf("目錄已存在!n");return1;while(ttemp->next)ttemp=ttemp->next;if(strcmp(ttemp->filename,temp->filename)=0&&ttemp->isdir=1)printf("目錄已存在!n");return1;ttemp->next=temp;temp->parent=NULL;temp->child=NULL;temp->prev=ttemp;temp->next=NULL;printf(&
25、quot;目錄建立成功!n");return0;intcreate()temp=initnode("”,0);cin>>temp->filename;if(recent->child=NULL)temp->parent=recent;temp->child=NULL;recent->child=temp;temp->prev=temp->next=NULL;cout<<”文件創(chuàng)建成功!"<<endl;elsettemp=recent->child;if(strcmp(ttemp-&
26、gt;filename,temp->filename)=0&&ttemp->isdir=0)printf("文件已存在!n");return1;while(ttemp->next)ttemp=ttemp->next;if(strcmp(ttemp->filename,temp->filename)=0&&ttemp->isdir=0)printf("文件已存在!n");return1;ttemp->next=temp;temp->parent=NULL;temp->child=NULL;temp->prev=ttemp;temp->next=NULL;cout<<”文件建立成功!"<<endl;return0;intrun()cout<<"filesystem:"<<path<<">
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 軟件設(shè)計師備考常見問題將解答試題及答案
- 加強公司財務(wù)內(nèi)控的工作計劃
- 隨州市隨縣事業(yè)單位2025年統(tǒng)一公開招聘筆試歷年典型考題及考點剖析附帶答案詳解
- 硬件接口設(shè)計基礎(chǔ)知識試題及答案
- 行政管理考試知識體系建立:試題及答案
- 分布式系統(tǒng)的設(shè)計與實現(xiàn)能力測試試題及答案
- 重要信息處理軟件試題及答案參考
- 2025年VB編程的國際趨勢及試題與答案
- 個人理財中的倫理與責(zé)任計劃
- 質(zhì)量管理部門個人發(fā)展策略計劃
- 2025年河北省秦皇島市海港區(qū)中考一模數(shù)學(xué)試卷(原卷版+解析版)
- 2025年注冊測繪師考試測繪地理信息數(shù)據(jù)處理與應(yīng)用試題
- 二手車貨車合同協(xié)議書
- 2024-2025部編版小學(xué)道德與法治二年級下冊期末考試卷及答案
- 測井試題及答案完整版
- 人格性格測試題及答案
- 中西文化鑒賞知到章節(jié)答案智慧樹2023年鄭州大學(xué)
- ASTM B465-20 銅鐵合金板、薄板、帶材和軋制棒材的標(biāo)準(zhǔn)規(guī)范
- 鐵路貨車運用常見故障講課講稿
- 公共場所重大活動衛(wèi)生監(jiān)督工作規(guī)范模板
- 大學(xué)計算機python選擇填空題庫及答案
評論
0/150
提交評論