实验四 文件系统实验Word格式.docx

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

实验四 文件系统实验Word格式.docx

《实验四 文件系统实验Word格式.docx》由会员分享,可在线阅读,更多相关《实验四 文件系统实验Word格式.docx(54页珍藏版)》请在冰点文库上搜索。

实验四 文件系统实验Word格式.docx

读写指针

·

文件系统算法的流程图如下:

三. 

实验题:

1、增加2~3个文件操作命令,并加以实现。

(如移动读写指针,改变文件属性,更换文件名,改变文件保护级别)。

代码如下:

//1、增加2~3个文件操作命令,并加以实现。

#include<

iostream>

string>

conio.h>

usingnamespacestd;

structTYPE_UFD

{

stringFile_Name;

boolRead;

boolWrite;

boolExecute;

intLength_File;

};

structTYPE_MFD

stringUser_Name;

TYPE_UFD*Pointer;

structTYPE_AFD

intFile_ID;

intPointer;

classTYPE_FILE_SYSTEM

public:

voidInitial(void);

voidStart(void);

private:

int_Number_Users;

int_Number_Files;

int_MaxNumber_Open_Files;

TYPE_MFD*_MFD;

TYPE_UFD*_UFD;

TYPE_AFD*_AFD;

voidTYPE_FILE_SYSTEM:

:

Initial(void)

_Number_Users=10;

_Number_Files=10;

_MaxNumber_Open_Files=5;

_UFD=newTYPE_UFD[_Number_Users*_Number_Files];

_MFD=newTYPE_MFD[_Number_Users];

inti=0;

for(i=0;

i<

_Number_Users;

i++)

{

_MFD[i].Pointer=&

(_UFD[i*_Number_Files]);

}

_AFD=newTYPE_AFD[_MaxNumber_Open_Files];

_MFD[0].User_Name="

zaq"

;

_UFD[0].File_Name="

file1.txt"

_UFD[0].Length_File=10;

_UFD[0].Read=true;

_UFD[0].Write=false;

_UFD[0].Execute=true;

_UFD[1].File_Name="

file2.txt"

_UFD[1].Length_File=20;

_UFD[1].Read=true;

_UFD[1].Write=false;

_UFD[1].Execute=false;

for(i=2;

_Number_Files;

_UFD[i].File_Name="

"

_UFD[i].Length_File=-1;

_UFD[i].Read=false;

_UFD[i].Write=false;

_UFD[i].Execute=false;

}

Start(void)

intUser_ID;

inti,temp_int;

stringtemp;

charchoice;

intNumber_Open_Files;

stringUser_Name;

stringCommand;

TYPE_UFD*UFD;

do

cout<

<

"

已创建用户名为zaq\n指令有:

createdeleteopendirdiropenwritereadlogoutshutdown\n\n"

请输入用户名:

cin>

>

User_Name;

for(User_ID=0;

User_ID<

User_ID++)

if(_MFD[User_ID].User_Name==User_Name)

break;

if(User_ID==_Number_Users)

用户名错误,请再次输入."

<

endl;

while(User_ID==_Number_Users);

欢迎登录,"

User_Name<

!

UFD=_MFD[User_ID].Pointer;

_MaxNumber_Open_Files;

_AFD[i].File_ID=-1;

Number_Open_Files=0;

C:

\\"

;

Command;

if(Command=="

dir"

打开用户"

的文件"

\t"

State\t"

Length\t"

Filename"

if(UFD[i].Length_File!

=-1)

if(UFD[i].Read==true)

R"

else

-"

if(UFD[i].Write==true)

W"

if(UFD[i].Execute==true)

E"

UFD[i].Length_File;

UFD[i].File_Name<

elseif(Command=="

diropen"

endl;

OpenFilename"

if(_AFD[i].File_ID!

if(_AFD[i].Read==true)

if(_AFD[i].Write==true)

if(_AFD[i].Execute==true)

UFD[_AFD[i].File_ID].File_Name<

create"

if(UFD[i].Length_File==-1)

if(i==_Number_Files)

Error:

已有名为"

_Number_Files<

的文件."

请输入新文件信息:

文件名:

temp;

UFD[i].File_Name=temp;

文件权限:

Read(y/n):

choice=getch();

while(choice!

='

y'

&

&

choice!

n'

);

if(choice=='

UFD[i].Read=true;

UFD[i].Read=false;

Write(y/n):

UFD[i].Write=true;

UFD[i].Write=false;

Execute(y/n):

UFD[i].Execute=true;

UFD[i].Execute=false;

Length:

temp_int;

if(temp_int>

0)

UFD[i].Length_File=temp_int;

新文件"

已建立!

delete"

请输入文件名:

if((UFD[i].Length_File!

=-1)&

(UFD[i].File_Name==temp))

文件名错误,请再次输入."

UFD[i].Length_File=-1;

文件"

已删除."

open"

if(Number_Open_Files==_MaxNumber_Open_Files)

你已经打开了"

Number_Open_Files<

文件."

请输入文件名:

Number_Open_Files++;

for(temp_int=0;

temp_int<

temp_int++)

if(_AFD[temp_int].File_ID==-1)

_AFD[temp_int].File_ID=i;

_AFD[temp_int].Pointer=0;

请定义打开方式:

_AFD[temp_int].Read=true;

_AFD[temp_int].Read=false;

_AFD[temp_int].Write=true;

_AFD[temp_int].Write=false;

_AFD[temp_int].Execute=true;

_AFD[temp_int].Execute=false;

_AFD[temp_int].Execute;

temp<

已打开."

logout"

再见,"

close"

if(_AFD[temp_int].File_ID==i)

if(temp_int==_MaxNumber_Open_Files)

未打开."

_AFD[temp_int].File_ID=-1;

Number_Open_Files--;

已关闭."

read"

if(_AFD[temp_int].Read==true)

成功读取."

文件打开模式错误."

write"

if(_AFD[temp_int].Write==true)

成功写入."

shutdown"

正在注销........"

正在关机.........."

指令错误,请再次输入."

while(Command!

="

Command!

intmain()

TYPE_FILE_SYSTEMFS;

FS.Initial();

FS.Start();

return0;

2、编一个通过屏幕选择命令的文件管理系统,每屏要为用户提供足够的选择信息,不需要打入冗长的命令。

#include<

//2、编一个通过屏幕选择命令的文件管理系统,每屏要为用户提供足够的选择信息,不需要打入冗长的命令。

stdio.h>

stdlib.h>

string.h>

#definegetpch(type)(type*)malloc(sizeof(type))

voidSelect();

intuserNum=0;

structmdf

charuserName[20];

structufd*p;

}mdf[20];

structufd

charfileName[20];

charFile[50];

structufd*next;

}*fp,*tp,*p,*begin;

typedefstructufdUFD;

voidshow(UFD*f)

begin=f;

if(begin->

next==NULL)

printf("

该用户名下尚无文件!

\n"

);

该用户名下所有文件:

begin=begin->

next;

while(begin!

=N

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

当前位置:首页 > 农林牧渔 > 林学

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

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