操作系统-实验四-可变分区存储管理

上传人:飞*** 文档编号:47465594 上传时间:2018-07-02 格式:PDF 页数:13 大小:192.22KB
返回 下载 相关 举报
操作系统-实验四-可变分区存储管理_第1页
第1页 / 共13页
操作系统-实验四-可变分区存储管理_第2页
第2页 / 共13页
操作系统-实验四-可变分区存储管理_第3页
第3页 / 共13页
操作系统-实验四-可变分区存储管理_第4页
第4页 / 共13页
操作系统-实验四-可变分区存储管理_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《操作系统-实验四-可变分区存储管理》由会员分享,可在线阅读,更多相关《操作系统-实验四-可变分区存储管理(13页珍藏版)》请在金锄头文库上搜索。

1、-1- 昆明理工大学信息工程与自动化学院学生实验报告( 2010 2011 学年第二学期 )课程名称:操作系统开课实验室:计算机中心204 2010年 06 月 03 日专业、年级、班学号姓名成绩实验项目名称可变分区存储管理指导教师教师评语教师签名:年月日一、实验目的:加深对可变分区的存储管理的理解;提高用 C语言编制大型系统程序的能力,特别是掌握 C语言编程的难点: 指针和指针作为函数参数; 掌握用指针实现链表和在链表上的基本操作。二、实验原理及基本技术路线图(方框原理图)技术路线图:开始显示信息初始化根目录-2- Flag=1 While(flag) ) Gets(string) 将字符长

2、度赋给len Len=0 将 string 的内容赋给 command Command=cd 或 CD Command=creat Comm=1 执行 CD Comm=2 执行 creat Command=” error”是否是是否否-3- 三、所用仪器:vc+6.0 。四、试验方法、步骤:源程序:#include #include #include #include #include #include Command=del Command=lsall Command=md Command=rd Command=exit Comm=3 执行 del Comm=4 执行 lsall Comm=

3、5 执行 md Comm=6 执行 rd Comm=0 Flag=0 Comm=100 结束是是是是否否否否否是-4- / *目录和文件的结构定义* typedef struct node char name50; /*目录或文件的名字*/ int type; /*0代表目录, 1 代表普通文件*/ struct node *next; /*指向下一个兄弟结点的指针*/ struct node *sub; /*指向第一个子结点的指针*/ struct node *father; /*指向父结点的指针*/ int size; /*如果是文件则表示文件的大小*/ dirNode; dirNode

4、*workDir; /定义当前工作目录dirNode root; /定义根目录char path100; /定义路径信息void initial() /初始化函数 strcpy(root.name,“root“); /root为根文件的名称root.type=0; root.next=NULL; root.sub=NULL; root.father=NULL; root.size=0; workDir= strcpy(path,“root“); /将 root拷贝到路径path 中 / 初始化新结点函数dirNode *init() dirNode *p; p=new dirNode; /申请

5、空间strcpy(root.name,“); root.type=0; root.next=NULL; root.sub=NULL; root.father=NULL; root.size=0; return p; /1 改变目录void CD(char dirName) dirNode *p; int flag=0; 是-5- p=workDir-sub; if(p=NULL) couttype=0) if(!strcmp(p-name,dirName) flag=1; break; p=p-next; if(flag=1) workDir=p; strcat(path,“ “); strc

6、at(path,p-name); coutname,fileName); q-sub=NULL; q-type=1; q-next=NULL; q-father=workDir; q-size=fileSize; p=workDir-sub; if(p=NULL) workDir-sub=q; couttype=1) if(!strcmp(p-name,fileName) flag=1; coutnext; if(flag=0) p=workDir-sub; while(p-next) p=p-next; p-next=q; coutsub; if(p=NULL) couttype=1) if

7、(!strcmp(p-name,fileName) flag=1; break; p=p-next; if(flag=1) if(p=workDir-sub) workDir-sub=p-next; else q=workDir-sub; while(q-next!=p) -7- q=q-next; q-next=p-next; delete p; couttype=0) cout.setf(2); coutname“name“sizenext; void dirs(dirNode *p,char str) char newstr100; dirNode *q; coutsub) strcpy

8、(newstr,“); strcat(newstr,str); strcat(newstr,“); strcat(newstr,q-name); dirs(q-sub,newstr); -8- q=p; while(q-next) if(q-next-sub) strcpy(newstr,“); strcat(newstr,str); strcat(newstr,“ “); strcat(newstr,q-next-name); dirs(q-next-sub,newstr); q=q-next; / 显示所有目录void LSALL() dirNode *p; coutname,dirNam

9、e); q-sub=NULL; q-type=0; q-next=NULL; q-father=workDir; q-size=0; p=workDir-sub; if(p=NULL) workDir-sub=q; couttype=0) if(!strcmp(p-name,dirName) flag=1; coutnext; if(flag=0) p=workDir-sub; while(p-next) p=p-next; p-next=q; coutsub; if(p=NULL) couttype=0) if(!strcmp(p-name,dirName) flag=1; break; -

10、10- p=p-next; if(flag=1) if(p=workDir-sub) workDir-sub=p-next; else q=workDir-sub; while(q-next!=p) q=q-next; q-next=p-next; delete p; cout#“,path); scanf(“%s“,string); len=strlen(string); if(len=0) strcpy(command,“errer“); else s=NULL; /获得命令 s=strchr(string, ); /将 string中出现空格的位置的指针赋给s, 若没有,则返回 NULL

11、 if(s!=NULL) *s=0; strcpy(command,string); /将 string中的字符串拷贝到command中/ 测试命令类型if(!strcmp(command,“CD“)|!strcmp(command,“cd“) /比较 command的内容和 CD或 cd 是否相等 comm=1; /相等则另comm=1 else if(!strcmp(command,“CREATE“)|!strcmp(command,“create“) /比较 command的内容和 creat是否相等 comm=2; else if(!strcmp(command,“DEL“)|!str

12、cmp(command,“del“) comm=3; else if(!strcmp(command,“LSALL“)|!strcmp(command,“lsall“) comm=4; -12- else if(!strcmp(command,“MD“)|!strcmp(command,“md“) comm=5; else if(!strcmp(command,“RD“)|!strcmp(command,“rd“) comm=6; else if(!strcmp(command,“EXIT“)|!strcmp(command,“exit“) comm=0; else comm=100; swi

13、tch(comm) case 1: strcpy(name,s+1); CD(name); break; case 2: s1=strchr(s+1, );/2 创建文件*s1=0; strcpy(name,s+1); fileSize=atoi(s1+1); CREATE(name,fileSize); break; case 3: strcpy(name,s+1);/3 删除文件DEL(name); break; case 4: LSALL();/4 显示目录break; case 5: strcpy(name,s+1);/5 创建目录MD(name); break; case 6: strcpy(name,s+1);/6 删除目录RD(name); -13- break; case 0: flag=0; /0 退出系统break; default: cout“ 命令错误 “endl; 五、实验过程原始记录:六、实验总结:通过本次试验,我对课本上文件的知识有了根深的了解,对文件的的具体操作也有了更进一步的认 识,对树形结构也得到了复习,这次编程中大量指针的运用也让我对指针的运用更熟练了,虽然我的编 程能力还很差,但是我相信,在今后的学习中,通过不断的编程和老师的讲解,我一定可以慢慢的提高。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号