




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
调度算法实验计算机科学与技术学院计0810813022022 杨文章实验目的:1. 掌握进程控制块的概念,理解基本的进程调度算法。实验内容:1. FCFS2. 短作业优先算法3. 优先级调度算法4最高响应比调度算法实验源程序:#include #include #include using namespace std;class JOB /定义作业数据结构体public:int number; /作业个数int reach_time; /作业到达时间int reach_hour; int reach_minite; int need_time; /作业运行时间int privilege; /优先级float excellent; int start_time; /开始时间int wait_time; /等待时间int visited; /已读取次数public:JOB()number=0;reach_time=0;reach_hour=0;reach_minite=0;need_time=0;privilege=0;excellent=0.0;start_time=0;wait_time=0;visited=0;JOB& Copy(JOB js)int i=0;while(jsi.number&jsi.number0)i+;JOB *js2=new JOBi;for(int j=0;jCopy (job);int current_hour; int current_minute; int total_time=0; /输出作业流 coutendl; coutendlFIFO调度算法:endl; cout.setf(2); coutsetw(10)作业号:setw(12)到达时间:setw(12)开始时间:setw(14)周转时间(分):endl; current_hour=jobs0.reach_hour; current_minute=jobs0.reach_minite; for(int i=0;iquantity;i+) jobsi.start_time=current_hour*100+current_minute; jobsi.wait_time=(current_hour-jobsi.reach_hour)*60+(current_minute-jobsi.reach_minite)+jobsi .need_time; coutsetw(10)jobsi.numbersetw(12)jobsi.reach_timesetw(12)jobsi.start_timesetw(14)jobsi.wait_timeendl; current_hour=current_hour+(jobsi.need_time+current_minute)/60; current_minute=(jobsi.need_time+current_minute)%60; total_time+=jobsi.wait_time; coutendl总周转时间:total_time 平均周转时间:total_time/quantityCopy (job);int i,j,p; int current_hour; int current_minute; int current_need_time; int total_time=0; /输出作业流 coutendl; coutendl时间短作业优先算法:endl; cout.setf(2); coutsetw(10)作业号:setw(12)到达时间:setw(14)所需时间(分):setw(12)开始时间:setw(14)周转时间(分):endl; current_hour=jobsquantity-1.reach_hour; current_minute=jobsquantity-1.reach_minite; for(i=0;iquantity;i+) current_need_time=30000; for(j=0;jquantity;j+) if(jobsj.visited=0)&(jobsj.need_timecurrent_need_time) p=j; current_need_time=jobsj.need_time; jobsp.start_time=current_hour*100+current_minute; jobsp.wait_time=(current_hour-jobsp.reach_hour)*60+(current_minute-jobsp.reach_minite)+jobsp .need_time; coutsetw(10)jobsp.numbersetw(12)jobsp.reach_timesetw(14)jobsp.need_timesetw(12)jobsp.start_timesetw(14)jobsp.wait_timeendl; current_hour=current_hour+(jobsp.need_time+current_minute)/60; current_minute=(jobsp.need_time+current_minute)%60; jobsp.visited=1; total_time+=jobsp.wait_time; coutendl总周转时间:total_time 平均周转时间:total_time/quantityCopy (job);int i,j,p; int current_hour; int current_minute; int current_privilege; int total_time=0; /输出作业流 coutendl; coutendl优先数调度算法:endl; cout.setf(2); coutsetw(10)作业号:setw(12)到达时间:setw(14)1):setw(12)开始时间:setw(14)周转时间(分):endl; current_hour=jobsquantity-1.reach_hour; current_minute=jobsquantity-1.reach_minite; for(i=0;iquantity;i+) current_privilege=30000; for(j=0;jquantity;j+) if(jobsj.visited=0)&(jobsj.privilegecurrent_privilege) p=j; current_privilege=jobsj.privilege; jobsp.start_time=current_hour*100+current_minute; jobsp.wait_time=(current_hour-jobsp.reach_hour)*60+(current_minute-jobsp.reach_minite)+jobsp .need_time; coutsetw(10)jobsp.numbersetw(12)jobsp.reach_timesetw(14)jobsp.privilegesetw(12)jobsp.start_timesetw(14)jobsp.wait_timeendl; current_hour=current_hour+(jobsp.need_time+current_minute)/60; current_minute=(jobsp.need_time+current_minute)%60; jobsp.visited=1; total_time+=jobsp.wait_time; coutendl总周转时间:total_time 平均周转时间:total_time/quantityCopy (job);int i,j,p; int current_hour; int current_minute; float current_excellent; int total_time=0; /输出作业流 coutendl; coutendl响应比高者优先调度算法:endl; cout.setf(2); coutsetw(10)作业号setw(12)到达时间setw(12)开始时间setw(14)周转时间(分)endl; current_hour=jobsquantity-1.reach_hour; current_minute=jobsquantity-1.reach_minite; for(i=0;iquantity;i+) current_excellent=-1; for(j=0;jquantity;j+) if(jobsj.visited=0) jobsj.wait_time=(current_hour-jobsj.reach_hour)*60+(current_minute-jobsj.reach_minite); jobsj.excellent=(float)(jobsj.wait_time/jobsj.need_time); for(j=0;jcurrent_excellent) p=j; current_excellent=jobsj.excellent; jobsp.start_time=current_hour*100+current_minute; jobsp.wait_time=(current_hour-jobsp.reach_hour)*60+(current_minute-jobsp.reach_minite)+jobsp .need_time; coutsetw(10)jobsp.numbersetw(12)jobsp.reach_timesetw(12)jobsp.start_timesetw(14)jobsp.wait_timeendl; current_hour=current_hour+(jobsp.need_time+current_minute)/60; current_minute=(jobsp.need_time+current_minute)%60; jobsp.visited=1; total_time+=jobsp.wait_time; coutendl总周转时间:total_time 平均周转时间:total_time/quantityendl; int main(void) cout*调度模拟*nnnendl;int quantity=0; /数量JOB jobsMAXJOB; coutfname; fp=fopen(fname,r);/以只读方式打开文件if(!fp) cout打开文件错误!)endl; elsewhile(!feof(fp) fscanf(fp,%d %d %d %d,&jobsquantity.number,&jobsquantity.reach_time,&jobsquantity.need_time,&jobsquantity.privilege);jobsquantity.reach_hour=jobsquantity.reach_time/100; jobsquantity.reach_minite=jobsquantity.reach_time%100; quantity+; /输出初始作业数据 cout初始作业数据:endl; cout.setf(2); coutsetw(10)作业号:setw(12)到达时间:setw(14)所需时间(分):setw(14)1)endl; for(int i=0;iquantity;i+) coutsetw(10)jobsi.numbersetw(12)jobsi.reach_timesetw(14)jobsi.need_timesetw(14)jobsi.privilegeendl; lb:cout请选择调度算法:n;couttt1-先进先出调度算法n;couttt2-短作业优先n;couttt3-优先级调度算法n;couttt4-响应比最高调度算法flag;switch (flag)case 1:FIFO(jobs,quantity); break;/先进先出调度算法case 2:Shorter(jobs,quantity);break;/短作业优先case 3:Privilege(jobs,quantity);break; /优先级调度算法case 4:Excellent(jobs,quantity);break; /响应比最高调度算法default:cout请输入1-4之间的数endl;goto lb;goto la;return 0;数据文件:data.txt1 700 40 12 723 32 23 821 25 34 823 21 45 900 15 66 912 10 47 930 51 5总结及程序简介:1 首先将数据存在data.tx
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 菏泽银行面试题目及答案
- 2025年注册验船师资格考试(A级船舶检验专业基础环境与人员保护)综合试题及答案一
- 北京市门头沟区2023-2024学年七年级下学期第一次月考英语考试题目及答案
- 2025年图书馆管理员招聘面试模拟题及答题技巧
- 2025年医疗器械质量认证考试全真模拟题
- 2025年财务风险管理师高级实务操作手册及考试指南
- 2025年高空作业平台设计与使用技能考试题库及答案
- 2025年高中物理学科知识与教学能力面试题解
- 2025年政府机关招聘行政岗位笔试模拟题及答案
- 2026届江苏省无锡江阴市化学高三上期末教学质量检测模拟试题含解析
- 《现场管理培训》课件
- 下颌骨骨折护理查房
- 基于无人机的公路平整度与车辙自动检测
- 医疗大数据共享平台
- 有限空间作业审批表
- 0.4kV不停电作业资质认证练习试题及答案
- 高一离子方程式书写专题训练及答案
- 北京市海淀区2020-2021学年七年级下学期期末历史试题(答案)
- 铲车司机安全生产岗位责任制
- 新媒体运营PPT完整全套教学课件
- 渝20TJ11 浮筑楼板隔声保温系统构造 难燃型改性聚乙烯复合卷材(蜂窝型)DJBT 50-143
评论
0/150
提交评论