




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、院 系:計(jì)算機(jī)科學(xué)學(xué)院專 業(yè):軟件工程年 級(jí): 2018 級(jí)課程名稱:操作系統(tǒng)指導(dǎo)教師:帖軍學(xué) 號(hào):2018姓 名:惺惺惜惺惺2020年4 月25 日年級(jí)2018專業(yè)軟件工程班級(jí)實(shí)驗(yàn) 名稱文件系統(tǒng)模擬實(shí)驗(yàn)內(nèi)容設(shè)一個(gè)簡(jiǎn)單的多用戶文件系統(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)程序米用二級(jí)文件目錄(即設(shè)置主目錄MFD)和用戶文件目錄(UFD)o 另外,為打開文件設(shè)置了運(yùn)行文件目錄(AFD)。(2)為了便于實(shí)現(xiàn),可以對(duì)文件讀寫作進(jìn)行簡(jiǎn)化,在執(zhí)行讀
2、寫命令時(shí),只 需改讀寫指針,并不進(jìn)行實(shí)際的讀寫操作。(3)文件目錄的檢索使用簡(jiǎn)單的線性搜索即可。(4)其他自行設(shè)定的要求條件。成 績(jī) 評(píng) 定教師簽名:年月日1文件系統(tǒng)模擬能設(shè)計(jì)一個(gè)簡(jiǎn)單的多用戶文件系統(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):"""鏈表長(zhǎng)度"""# 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('請(qǐng)輸入第用戶名:'.format(i) create_user(name)print('用戶創(chuàng)建成功'.format(name) else:user = input('請(qǐng)輸入要登陸的用戶名:')Jud = MFD.search(user) if Jud is True: print('登錄成功!') count = 1else:print('用戶不存在!) else:user = inpu
12、t('請(qǐng)輸入要登陸的用戶名:')Jud = MFD.search(user) if Jud is True:print('登錄成功!,) count = 1else:print('用戶不存在!,)def create_file():# 創(chuàng)建文件global countif count = 0:print('請(qǐng)先登錄!,)else:file = input('請(qǐng)輸入要?jiǎng)?chuàng)建的文件名:')UFD.append(file) print('文件創(chuàng)建成功,)def open_file():global countif count = 0:pr
13、int('請(qǐng)先登錄!,)else:file = input('請(qǐng)輸入要打開的文件名:,)if UFD.is_empty() is True: print('請(qǐng)先創(chuàng)建文件:,)elif UFD.search(file) is False:print('該文件不存在,請(qǐng)先創(chuàng)建!,)else:AFD.append(file) print('文件已打開,)def close_file():global countif count = 0:print('請(qǐng)先登錄!,)else:file = input('請(qǐng)輸入要關(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('請(qǐng)先登錄!,)else:file = input('請(qǐng)輸入要讀取的文件:')if AFD.search(file) is False:print('文件沒有打開,)else:print('文件已讀取,)def write_file():global countif count = 0:print(
15、9;請(qǐng)先登錄!,)else:file = input(,請(qǐng)輸入要寫入的文件:')if AFD.search(file) is False:print('文件沒有打開,)else:print('文件已寫入,)def delete_file():global countif count = 0:print('請(qǐng)先登錄!,)else:file = input(,請(qǐng)輸入要?jiǎng)h除的文件:')if UFD.search(file) is False:print('文件不存在!,)else:UFD.remove(file)print('文件已刪除!,)m
16、ain_menu.py 文件#主菜單文件def menu():# 菜單print('*二級(jí)文件系統(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('請(qǐng)輸入命令:')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()嚙*#* * *擊*二級(jí)文件 系統(tǒng)涓示或1*1*1嘯女*/*±*叩說明login登錄系統(tǒng)create創(chuàng)建文件open打開攵件close關(guān)詡文件read試取文件write寫入文件del
溫馨提示
- 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 電源產(chǎn)品采購(gòu)合同范本
- 水泥浮雕墻合同范本
- 長(zhǎng)途司機(jī)雇傭合同范本
- 云南2025年02月昆明市事業(yè)單位公開招考工作人員筆試歷年典型考題(歷年真題考點(diǎn))解題思路附帶答案詳解
- 修建水庫(kù)合同范本
- 建設(shè)工程保修合同范本
- 供水轉(zhuǎn)讓合同范本
- 夫妻財(cái)產(chǎn)合同范本
- 工程采購(gòu)服務(wù)合同范本
- 新世紀(jì)以來澳大利亞能源轉(zhuǎn)型研究
- 2023年蘇州健雄職業(yè)技術(shù)學(xué)院?jiǎn)握锌荚嚸嬖囶}庫(kù)及答案解析
- 公司組織架構(gòu)圖(可編輯模版)
- 人教版六年級(jí)科學(xué)下冊(cè)教案全冊(cè)
- TCITSA 24-2022 基于ETC的高速公路自由流收費(fèi)技術(shù)規(guī)范
- 叉車裝卸區(qū)域安全風(fēng)險(xiǎn)告知牌
- 2022屆江蘇省南京師范大學(xué)附屬中學(xué)高三(下)考前最后一模物理試題(解析版)
- 《普通生物學(xué)教案》word版
- 貴州省就業(yè)失業(yè)登記表
- 預(yù)防電信詐騙網(wǎng)絡(luò)詐騙講座PPT幻燈片課件
- 反興奮劑知識(shí)試題及答案
- 初中八年級(jí)上冊(cè)音樂課件4.2欣賞沃爾塔瓦河(14張)ppt課件
評(píng)論
0/150
提交評(píng)論