版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、院 系:計(jì)算機(jī)科學(xué)學(xué)院專 業(yè):軟件工程年 級: 2018 級課程名稱:操作系統(tǒng)指導(dǎo)教師:帖軍學(xué) 號(hào):2018姓 名:惺惺惜惺惺2020年4 月25 日年級2018專業(yè)軟件工程班級實(shí)驗(yàn) 名稱文件系統(tǒng)模擬實(shí)驗(yàn)內(nèi)容設(shè)一個(gè)簡單的多用戶文件系統(tǒng)。在系統(tǒng)中用一個(gè)文件來模擬一個(gè)磁盤;此系統(tǒng)至少有:Create delete opens close read write等和部分文件 屬性的功能。實(shí)現(xiàn)這個(gè)文件系統(tǒng)。能實(shí)際演示這個(gè)文件系統(tǒng)。(1)程序米用二級文件目錄(即設(shè)置主目錄MFD)和用戶文件目錄(UFD)o 另外,為打開文件設(shè)置了運(yùn)行文件目錄(AFD)。(2)為了便于實(shí)現(xiàn),可以對文件讀寫作進(jìn)行簡化,在執(zhí)行讀
2、寫命令時(shí),只 需改讀寫指針,并不進(jìn)行實(shí)際的讀寫操作。(3)文件目錄的檢索使用簡單的線性搜索即可。(4)其他自行設(shè)定的要求條件。成 績 評 定教師簽名:年月日1文件系統(tǒng)模擬能設(shè)計(jì)一個(gè)簡單的多用戶文件系統(tǒng)。在系統(tǒng)中用一個(gè)文件來模擬一個(gè)磁盤;此系統(tǒng)至少有:Create delete、opens close read whte等和部分文 件屬性的功能。實(shí)現(xiàn)這個(gè)文件系統(tǒng)。能實(shí)際演示這個(gè)文件系統(tǒng)。具體題目: 文件系統(tǒng)模擬 系統(tǒng)平臺(tái):Windows程序中使用的主要設(shè)計(jì)結(jié)構(gòu)如下:主文件目錄和用戶文件目錄( MFD、UFD),打開實(shí)驗(yàn)原理步驟算法流程文件目錄(AFD)即運(yùn)行文件目錄,如圖所示。文件系統(tǒng)結(jié)構(gòu)如圖所
3、示源代碼:Single_link_list.py 文件#血class Node(object):"""結(jié)點(diǎn)"""def _init_(self, elem):self.elem = elemself.next = Noneclass SingleLinkList(object):"""單鏈表"""def _init_(self, node=None):self._head = nodedef is_empty(self):"""鏈表是否為空&qu
4、ot;""return self._head is Nonedef length(self):"""鏈表長度"""# cur游標(biāo),用來移動(dòng)遍歷結(jié)點(diǎn)cur = self._head# count記錄數(shù)值count = 0while cur is not None:count += 1 cur = cur.nextreturn countdef travel(self):"""遍歷整個(gè)鏈表"""cur = self._headwhile cur is not
5、None: print(cur.elem, end="") cur = cur.nextprint("")def add(self, item):"""鏈表頭部添加元素"""node = Node(item) node.next = self._head self._head = nodedef append(self, item):"""鏈表尾部添加元素"""node = Node(item)if self.is_empty():se
6、lf._head = nodeelse:cur = self._headwhile cur.next is not None: cur = cur.nextcur.next = nodedef insert(self, pos, item):"""指定位置添加元素:param pos 從 0 開始 """if pos <= 0: self.add(item)elif pos > (self.length() - 1): self.append(item)else:pre = self._headcount = 0while
7、 count < (pos - 1):count += 1 pre = pre.next#當(dāng)循環(huán)退出后,pre指向pos-1位直 node = Node(item)node.next = pre.nextpre.next = nodedef remove(self, item):"""刪除結(jié)點(diǎn)"""cur = self._headpre = Nonewhile cur is not None:if cur.elem = item:#先判斷此節(jié)點(diǎn)是否是頭節(jié)點(diǎn)#頭結(jié)點(diǎn)if cur = self._head:self._head =
8、cur.nextelse:pre.next = cur.next breakelse:pre = cur cur = cur.nextdef search(self, item):"""查找結(jié)點(diǎn)是否存在"""cur = self._headwhile cur is not None:if cur.elem = item:return Trueelse:cur = cur.nextreturn FalseDirectory.py 文件#程序函數(shù)import Single_link_list as Ccount = 0MFD = C.Si
9、ngleLinkList()# 主目錄UFD = C.SingleLinkList()# 用戶義件目錄AFD = C.SingleLinkList()# 運(yùn)行文件目錄def create user(name): # 創(chuàng)建用戶MFD.append(name) write_user(name)def write_user(name): #將用戶添加到磁盤 with open('D:/Python/OS/MFD.txt', 'a') as f: f.write(name) f.write('r')def read_user(): #將磁盤文件讀取 f
10、= open('D:/Python/OS/MFD.txt', 'r') for line in f.readlines():line = line.strip()MFD.append(line) f.close()def login_a():# 登錄函數(shù)global countper = MFD.is_empty()if per is True: read_user() per = MFD.is_empty() if per is True:sur = input('沒有用戶,是否創(chuàng)建(y/n) !') if sur = 'y':
11、a = int(input('創(chuàng)建用戶數(shù):')for i in range(1, a+1):name = input('請輸入第用戶名:'.format(i) create_user(name)print('用戶創(chuàng)建成功'.format(name) else:user = input('請輸入要登陸的用戶名:')Jud = MFD.search(user) if Jud is True: print('登錄成功!') count = 1else:print('用戶不存在!) else:user = inpu
12、t('請輸入要登陸的用戶名:')Jud = MFD.search(user) if Jud is True:print('登錄成功!,) count = 1else:print('用戶不存在!,)def create_file():# 創(chuàng)建文件global countif count = 0:print('請先登錄!,)else:file = input('請輸入要?jiǎng)?chuàng)建的文件名:')UFD.append(file) print('文件創(chuàng)建成功,)def open_file():global countif count = 0:pr
13、int('請先登錄!,)else:file = input('請輸入要打開的文件名:,)if UFD.is_empty() is True: print('請先創(chuàng)建文件:,)elif UFD.search(file) is False:print('該文件不存在,請先創(chuàng)建!,)else:AFD.append(file) print('文件已打開,)def close_file():global countif count = 0:print('請先登錄!,)else:file = input('請輸入要關(guān)閉的文件:,)if AFD.sea
14、rch(file) is False: print('文件沒有打開!,)else:AFD.remove(file)print('文件已關(guān)閉!,)def read_file():global countif count = 0:print('請先登錄!,)else:file = input('請輸入要讀取的文件:')if AFD.search(file) is False:print('文件沒有打開,)else:print('文件已讀取,)def write_file():global countif count = 0:print(
15、9;請先登錄!,)else:file = input(,請輸入要寫入的文件:')if AFD.search(file) is False:print('文件沒有打開,)else:print('文件已寫入,)def delete_file():global countif count = 0:print('請先登錄!,)else:file = input(,請輸入要?jiǎng)h除的文件:')if UFD.search(file) is False:print('文件不存在!,)else:UFD.remove(file)print('文件已刪除!,)m
16、ain_menu.py 文件#主菜單文件def menu():# 菜單print('*二級文件系統(tǒng),MtF*')print('命令說明1)print('login登錄系統(tǒng)1)print('create創(chuàng)建文件,)print('open打開文件')print('close關(guān)閉文件')print('read讀取文件')print('write寫入文件')print('delete刪除文件')print('quit退出系統(tǒng)print('*)main.py#主函數(shù)文件
17、import main_menu as Aimport Directory as B')def main():# 主函數(shù)A.menu()cmd = input('請輸入命令:')L = 'login', 'create', 'open', 'close', 'read', 'write', 'delete', 'quit' if cmd = L0:B.login_a()main()elif cmd = L1:B.create_file()mai
18、n()elif cmd = L2:B.open_file()main()elif cmd = L3:B.close_file()main()elif cmd = L4:B.read_file()main()elif cmd = L5:B.write_file()main()elif cmd = L6:B.delete_file()main()elif cmd = L7:print('謝謝使用!)else:print('命令輸入錯(cuò)誤!')main()if _name_ = "_main_": main()嚙*#* * *擊*二級文件 系統(tǒng)涓示或1*1*1嘯女*/*±*叩說明login登錄系統(tǒng)create創(chuàng)建文件open打開攵件close關(guān)詡文件read試取文件write寫入文件del
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年醫(yī)療設(shè)備維修合同
- 2025年倉儲(chǔ)租金費(fèi)用合同
- 2025年家居和解協(xié)議書
- 2025年在線音樂電臺(tái)服務(wù)合約
- 2025年企業(yè)員工靈活用工管理服務(wù)合同
- 2025年分期付款游泳館會(huì)員購買合同
- 2025年度二零二五年度獼猴桃產(chǎn)業(yè)鏈金融服務(wù)平臺(tái)合作合同4篇
- 2025版小公司租車及車輛租賃售后服務(wù)合同2篇
- 二零二五版醫(yī)院康復(fù)病區(qū)承包服務(wù)協(xié)議2篇
- 二零二五年度木地板綠色環(huán)保材料采購合同4篇
- 光伏自發(fā)自用項(xiàng)目年用電清單和消納計(jì)算表
- 量子計(jì)算在醫(yī)學(xué)圖像處理中的潛力
- 阿里商旅整體差旅解決方案
- 浙江天臺(tái)歷史文化名城保護(hù)規(guī)劃說明書
- 邏輯思維訓(xùn)練500題
- 第八講 發(fā)展全過程人民民主PPT習(xí)概論2023優(yōu)化版教學(xué)課件
- 實(shí)體瘤療效評價(jià)標(biāo)準(zhǔn)RECIST-1.1版中文
- 企業(yè)新春茶話會(huì)PPT模板
- GB/T 19185-2008交流線路帶電作業(yè)安全距離計(jì)算方法
- DIC診治新進(jìn)展課件
- 公路工程施工現(xiàn)場安全檢查手冊
評論
0/150
提交評論