#include "stdlib.h"
#include "stdio.h"
#include "iostream.h"
#include "string.h"
#define NULL 0
int count=0;
struct file{
char name[10];
int code;//保护码
int size;
char pwrite;//读写指针
};
struct user{
char name[10];
struct file *list;//目录指针
};
/////////////////////////////////////////////////////////////
struct file one[10]={{"a1",0,10,0},{"a2",2,10,0},{"a3",1,10,0},
{"a4",2,10,0},{"a5",2,10,0},{"a6",2,10,0},{"a7",1,10,0},{"0",0,0,0},
{"0",0,0,0},{"0",0,0,0}};
struct file two[10]={{"b1",0,10,0},{"b2",2,10,0},{"b3",1,10,0},
{"b4",2,10,0},{"b5",2,10,0},{"b6",2,10,0},{"b7",2,10,0},{"0",0,0,0},
{"0",0,0,0},{"0",0,0,0}};
struct file three[10]={{"c1",0,10,0},{"c2",2,10,0},{"c3",1,10,0},
{"c4",2,10,0},{"c5",2,10,0},{"c6",2,10,0},{"c7",1,10,0},{"0",0,0,0},
{"0",0,0,0},{"0",0,0,0}};
struct file four[10]={{"d1",0,10,0},{"d2",2,10,0},{"d3",1,10,0},
{"d4",2,10,0},{"d5",2,10,0},{"d6",2,10,0},{"d7",1,10,0},{"0",0,0,0},
{"0",0,0,0},{"0",0,0,0}};
struct file fine[10]={{"e1",0,10,0},{"e2",2,10,0},{"e3",1,10,0},
{"e4",2,10,0},{"e5",2,10,0},{"e6",2,10,0},{"e7",1,10,0},{"0",0,0,0},
{"0",0,0,0},{"0",0,0,0}};
struct file six[10]={{"f1",0,10,0},{"f2",2,10,0},{"f3",1,10,0},
{"f4",2,10,0},{"f5",2,10,0},{"f6",2,10,0},{"f7",1,10,0},{"0",0,0,0},
{"0",0,0,0},{"0",0,0,0}};
struct file seven[10]={{"g1",0,10,0},{"g2",2,10,0},{"g3",1,10,0},
{"g4",2,10,0},{"g5",2,10,0},{"g6",2,10,0},{"g7",1,10,0},{"0",0,0,0},
{"0",0,0,0},{"0",0,0,0}};
struct file eight[10]={{"h1",0,10,0},{"h2",2,10,0},{"h3",1,10,0},
{"h4",2,10,0},{"h5",2,10,0},{"h6",2,10,0},{"h7",1,10,0},{"0",0,0,0},
{"0",0,0,0},{"0",0,0,0}};
struct file nine[10]={{"j1",0,10,0},{"j2",2,10,0},{"j3",1,10,0},
{"j4",2,10,0},{"j5",2,10,0},{"j6",2,10,0},{"j7",1,10,0},{"0",0,0,0},
{"0",0,0,0},{"0",0,0,0}};
struct file ten[10]={{"k1",0,10,0},{"k2",2,10,0},{"k3",1,10,0},
{"k4",2,10,0},{"k5",2,10,0},{"k6",2,10,0},{"k7",1,10,0},{"0",0,0,0},
{"0",0,0,0},{"0",0,0,0}};
struct file UFD[10];
struct file AFD[5]={{"0",0,0,0},{"0",0,0,0},{"0",0,0,0},{"0",0,0,0},{"0",0,0,0}};
///////////////////////////////////////////////////////////////
struct user use[10]={{"number1",one},{"number2",two},{"number3",three},{"number4",four},
{"number5",fine},{"number6",six},{"number7",seven},{"number8",eight},{"number9",nine},
{"number10",ten}};
struct user MFD[1]={{"0",0}};
///////////////////////////////////////////////////////////////////
void running();
void delet();
void write();;
void open();
void close();
void bye();
void read(); 腾讯游戏客服
void create();
void input();
///////////////////////////////////////////////////////////////////
void mai
n()
{ input();
running();
cout<<"操作己结束"<<endl;
}
///////////////////////////////////////////////////////////// 回收站删除了怎么恢复
void running()
{ char order;
int i;
cout<<endl<<"******************************************************************************"<<endl;
cout<<"用户的所有文件如下:"<<endl;
for(i=0;i<10;i++)
{
cout<<UFD[i].name<<"\t";
}
cout<<endl<<"**************************************************************************"<<endl;
cout<<" 请选择操作命令(输入代号):"<<endl;
cout<<"c-create d-delete o-open s-close r-read w-write b-bye t.exit(重选用户)"<<endl;
cout<<endl<<"***************************************************************************"<<endl;
cout<<"请输入命令:"<<endl;
cin>>order;
switch(order)
{ case 'c' : create();break;
case 'd' : delet();break;
case 'o' : open();break;
case 's' : close();break;
case 'r' : read();break;
case 'w' : write();break;
case 'b' : bye();break;
case 't' : input();break;
default : cout<<"输入命令出错,请重输"<<endl<<endl;running();
}
}
/
//////////////////////////////////////////////////////////////
void delet()
{ char name[10];
int i,flag;
do
{ cout<<"请输入文件名: "<<endl<<endl;
cin>>name;
flag=0;
for(i=0;i<10;i++)
{ if(strcmp(UFD[i].name,name))//如果没有这个文件
{
flag=1;
//break;
}
else
{ flag=0;
strcpy(UFD[i].name,"0");//清空文件
UFD[i].code=0;
UFD[i].pwrite=0;
UFD[i].size=0;
cout<<"该文件己被删除"<<endl;
break;
夜夜夜漫长
}
}
if(flag==1)
cout<<"无此文件,请重新输入"<<endl;
}while(flag==1);
cout<<endl;
running();
}
///////////////////////////////////////////////
void open()
{ char name[10];
int i,j,flag;
if(count==5)
{ cout<<"运行文件队列己满"<<endl;
running();
}
else
{ do
{ cout<<"请输入文件名: "<<endl;
cin>>name;
flag=0;
for(i=0;i<10;i++)
{ if(strcmp(UFD[i].name,name))//如果没有这个文件
{
flag=1;
//break;
}
else
{ flag=0;
break;
}
}
if(flag==1)
cout<<"无此文件,请重新输入"<<endl;
}while(flag==1);
for(j=0;j<5;j++)
{ if(strcmp(AFD[j].name,name))//如果没有这个文件
flag=1;
else
{ flag=0;
break;
}
}
if(flag==1)
for(j=0;j<5;j++)
{ if(!strcmp(AFD[j].name,"0"))
{ AFD[j]=UFD[i];
cout<<"文件己打开"<<endl;
count++;
break;
}
}
else cout<<"该文件己经在打开队列中"<<endl;
cout<<endl;
running();
}
}
////////////////////////////////////////////////
void close()
{ char name[10];
int j,flag;
cout<<"请输入文件名: "<<endl;
cin>>name;
落叶归根歌词flag=0;
for(j=0;j<5;j++)
{ if(strcmp(AFD[j].name,name))//如果没有这个文件
{
flag=1;
//break;
}
else
{ flag=0;
strcpy(AFD[j].name,"0");//清空文件
AFD[j].code=0;
AFD[j].pwrite=0;
AFD[j].size=0;
cout<<"运行队列中的该文件己被关闭"<<endl;
break;
}
}
if(flag==1)
cout<<"运行队列中无此打开的文件,请重新操作"<<endl;
cout<<endl;
running();
}
//////////////////////////////////////////////
void bye()
{ int i,j;
for(i=0;i<5;i++)
{ for(j=0;j<10;j++)
{ if(!strcmp(AFD[i].name,UFD[j].name))
{ UFD[i]=AFD[i];
break;
}
}
}
cout<<"文件目录己保存"<<endl;
cout<<endl;
}
/
/////////////////////////////////////////
void read()
{ char name[10];
int j,flag=0;
cout<<"请输入文件名: "<<endl;
cin>>name;
for(j=0;j<5;j++)
{
if(!strcmp(AFD[j].name,name))//如果AFD有这个文件
{ flag=1; break;
}
}
if(flag==1)
if(AFD[j].code==0||AFD[j].code==2)
{ AFD[j].pwrite='R';
cout<<"文件的状态是正在读"<<endl;
}
else cout<<"无权限写此文件"<<endl;
else
{ cout<<"运行队列中无此文件,请先打开文件"<<endl;
}
cout<<endl;
running();
}
////////////////////////////////////////////////////////
void write()
{ char name[10];
int j,flag=0;
cout<<"请输入文件名: "<<endl;
cin>>name;
for(j=0;j<5;j++)
{
if(!strcmp(AFD[j].name,name))//如果AFD有这个文件
{ flag=1; break;
}
}
if(flag==1)
炫舞印象if(AFD[j].code==1||AFD[j].code==2)
{ AFD[j].pwrite='W';
cout<<"文件的状态是正在写"<<endl;
}
else cout<<"无权限写此文件"<<endl;
else
{ cout<<"运行队列中无此文件,请先打开文件"<<endl;
}
cout<<endl;
running();
}
/////////////////////////////////////////////
void create()
{ char name[10];
int i,j=0,flag;
for(i=0;i<10;i++)
{ if(!strcmp(UFD[i].name,"0"))
j++;
}
if(j>9)
{ cout<<"文件夹己满,请先删除"<<endl;//cout<<j;
running();
}
else
{
do
{ cout<<"请输入文件名: "<<endl;
cin>>name;
flag=0;
for(i=0;i<10;i++)
{ if(!strcmp(UFD[i].name,name))//如果有重名的文件
{ cout<<"文件名重复,请重新输入"<<endl;
flag=1; break;
}
}
}while(flag==1);
for(i=0;i<10;i++)
{ if(!strcmp(UFD[i].name,"0"))//到第一个空的文件
{ strcpy(UFD[i].name,name);
do
{
cout<<"请输入保护码(选择0-2,0-可读,1-可写,2-可读写):"<<endl;
cin>>UFD[i].code;
if(UFD[i].code!=0&&UFD[i].code!=1&&UFD[i].code!=2)
cout<<"输入错误,重新输入保护码"<<endl;
}while(UFD[i].code!=0&&UFD[i].code!=1&&UFD[i].code!=2);
cout<<"请输入文件长度(选择数字):"<<endl;
cin>>UFD[i].size;
cout<<"己建立文件"<<UFD[i].name<<endl;
break;
}
}
running();
}
}
////////////////////////////////////////////////////////////////////////////////////////////
void input()
{ char name;
int i;
cout<<endl<<"*******************************************************************************"<<endl;
cout<<" 请选择以下用户名(输入数字):"<<endl;
cout<<"1.one 2.two 3.three 4.four 5.fine 6.six 7.seven 8.eigh
< "<<endl;
cout<<"*******************************************************************************"<<endl<<endl;
cout<<"请输入用户名:";
cin>>name;
switch(name)
{ case '1': for(i=0;i<10;i++)UFD[i]=one[i];MFD[0]=use[1];running();break;
冯绍峰富二代case '2': for(i=0;i<10;i++)UFD[i]=two[i];MFD[0]=use[1];running();break;
case '3': for(i=0;i<10;i++)UFD[i]=three[i];MFD[0]=use[2];running();break;
case '4': for(i=0;i<10;i++)UFD[i]=four[i];MFD[0]=use[3];running();break;
case '5': for(i=0;i<10;i++)UFD[i]=fine[i];MFD[0]=use[4];running();break;
case '6': for(i=0;i<10;i++)UFD[i]=six[i];MFD[0]=use[5];running();break;
case '7': for(i=0;i<10;i++)UFD[i]=seven[i];MFD[0]=use[6];running();break;
case '8': for(i=0;i<10;i++)UFD[i]=eight[i];MFD[0]=use[7];running();break;
case '9': for(i=0;i<10;i++)UFD[i]=nine[i];MFD[0]=use[8];running();break;
case '0': for(i=0;i<10;i++)UFD[i]=ten[i];MFD[0]=use[9];running();break;
default : cout<<"输入用户名出错"<<endl;input();
}
}
发布评论