一、实验要求
1.用可视化编程工具编制程序,在机器上调试运行,并通过上机考核。
2.要求将功能集中在一个界面中,界面设计美观,功能完整,使用方便。

二、设计题目
题目1 进程调度模拟程序
目的:
熟悉进程调度算法及其实现
内容:
编写一个程序完成多道程序的调度
要求:
只考虑1个CPU的资源,其他资源不考虑
使用响应比高者优先算法
程序采用键盘输入,输入格式为:

K
TJ1 YS1
……
TJK YSK

其中K是作业数(>0),TJi提交时间,YSi (i=1~K)是作业预计的运行时间(以分钟计)TJ的输入格式是XXYY,
其中XX是时,YY是分,如10点28分,输入为1028。但内部计算要以60进制来算。要求输出按照作业调度的先后次序输出结果,
每行为一个作业状态,从左到右分别是调度次序,作业号,调度时间,周转时间和带权周转时间,
最后一行输出两个数,第一为平均周转时间,第二为平均带权周转时间。

#include<string.h>
#include<iostream>
using namespace std;struct PCB {int arrTime; /* 作业到达时间*/int serTime; /*作业要求服务时间*/int waiTime; /*等待时间*/int begTime; /*开始运行时间*/int finTime; /*结束运行时间*/float turTime; /*周转时间*/float wTuTime; /*带权周转时间*/int priority;/*优先权*/int finish;  /*是否已经完成*/
}PCB[10];int cnt;
int runningTime = 0;
int currentTime = 0;
void input()
{cout << "请输入作业数量: ";cin >> cnt;for (int i = 0;i < cnt;i++){cin >> PCB[i].arrTime >> PCB[i].serTime;PCB[i].priority = 1;PCB[i].finish = 0;}
}int Add(int a, int b)//得到时刻(xx:yy)(用于时刻+分钟)
{return (a / 100 + (a % 100 + b) / 60) * 100 + (a % 100 + b) % 60;
}
int Sub(int a, int b)//得到时长(min)(用于时刻-时刻)
{return (a / 100 - b / 100) * 60 + (a % 100 - b % 100);
}void HRN()
{int n = 0;int current, i, j;int min = 9999999;for (int m = 0; m< cnt; m++){if (PCB[m].arrTime < min){current = m;min = PCB[m].arrTime;}}cout << "调度情况如下:" << endl;cout << "调度次序" << " " << "作业号" << " " << "调度时间" << " " << "周转时间" << " " << "带权周转时间" << endl;PCB[current].turTime = PCB[current].serTime;PCB[current].wTuTime = PCB[current].serTime / PCB[current].serTime;PCB[current].begTime = PCB[current].arrTime;//输出调度次序,作业号,调度时间,周转时间和带权周转时间cout << ++n << "         " << current + 1 << "       " << PCB[current].begTime << "       "<< PCB[current].turTime << "       " << PCB[current].wTuTime << endl;PCB[current].finish = 1;runningTime += PCB[current].serTime;currentTime = currentTime + Add(PCB[current].arrTime, PCB[current].serTime);for (i = 0; i < cnt; i++){PCB[i].waiTime = Sub(currentTime, PCB[i].arrTime);PCB[i].priority += PCB[i].waiTime / PCB[i].serTime;}for (i = 0; i < cnt; i++){if (!PCB[i].finish && PCB[i].arrTime < currentTime){current = i;for (j = 0; j < cnt; j++){if (!PCB[j].finish && PCB[j].arrTime < currentTime && PCB[j].priority > PCB[current].priority)current = j;               }//输出PCB[current].turTime = Sub(currentTime, PCB[current].arrTime) + PCB[current].serTime;PCB[current].wTuTime = PCB[current].turTime / PCB[current].serTime;PCB[current].begTime = currentTime;cout << ++n << "         " << current + 1 << "       " << PCB[current].begTime << "       " << PCB[current].turTime<< "       " << PCB[current].wTuTime << endl;PCB[current].finish = 1;runningTime += PCB[current].serTime;currentTime = Add(currentTime, PCB[current].serTime);for (int l = 0; l < cnt; l++){if (!PCB[l].finish){PCB[l].waiTime = Sub(currentTime, PCB[l].arrTime);PCB[l].priority += PCB[l].waiTime / PCB[l].serTime;}}}else if (i == cnt - 1){int min = 9999999;for (int m = 0; m < cnt; m++){if (!PCB[m].finish&&PCB[m].arrTime < min){current = m;min = PCB[m].arrTime;}}currentTime = Add(currentTime, Sub(PCB[current].arrTime, currentTime));PCB[current].turTime = PCB[current].serTime;PCB[current].wTuTime = PCB[current].serTime / PCB[current].serTime;PCB[current].begTime = PCB[current].arrTime;//输出调度次序,作业号,调度时间,周转时间和带权周转时间cout << ++n << "         " << current + 1 << "       " << PCB[current].begTime << "       "<< PCB[current].turTime << "       " << PCB[current].wTuTime << endl;PCB[current].finish = 1;runningTime += PCB[current].serTime;currentTime = Add(currentTime, PCB[current].serTime);i = -1;  //重新开始寻找}}
}void main()
{input();HRN();float tur = 0;float wtu = 0;for (int i = 0;i < cnt;i++){tur += PCB[i].turTime;wtu += PCB[i].wTuTime;}cout << "平均周转时间和平均带权周转时间分别为:" << endl;cout << tur/cnt << "    " << wtu/cnt << endl;
}

觉得有用的话就点个赞吧,蟹蟹!!!

高响应比优先算法实现进程调度模拟相关推荐

  1. 作业调度算法【平均周转时间、平均带权周转时间、先来先服务FCFS、短作业优先SJF、高优先权(级)算法FPF、高响应比优先算法HRRN】

    文章目录 先来先服务算法(FCFS) 短作业优先算法(SJF).短进程优先算法(SPF) 周转时间和带权周转时间 高优先权(级)调度算法FPF 高响应比优先调度算法HRRN 先来先服务算法(FCFS) ...

  2. 高响应比优先算法代码_以梦为码丨让每一行代码都充满温情

    本期热点 智能校园部招聘专场 小海 小海冲鸭 我们一直在打磨的多款产品在上周海亮教育研究院产品发布会上崭露头角,激动!!! 别说话,我在敲代码 发布了哪些呀? 小海冲鸭 iClass.海亮星课堂.模板 ...

  3. C++、高响应比优先算法

    #include<iostream> #include"string" using namespace std; struct JOB {string name; // ...

  4. 先来先服务和高响应比优先调度算法C语言实现

    先来先服务和高响应比优先调度算法C语言实现 目录: 1.进程调度与作业调度的区别: 2.单道批处理系统与多道批处理系统的区别: 3.程序设计用到的公式: 4.高响应比优先算法特点: 5.源代码示例: ...

  5. 十一、FCFS(先来先服务)、SJF(短作业优先)、HRRN(高响应比优先)

    一.知识总览 二.先来先服务(FCFS) **注意:**针对于先来先服务算法某些作业(或进程)平均周转时间长的缺点,提出了短作业优先的算法(SJF) 三.短作业优先(SJF) 1.非抢占式的短作业优先 ...

  6. 作业调度算法--高响应比优先 操作系统_处理器管理_编程题

    操作系统_处理器管理_编程题 作业调度算法–高响应比优先 输入N个作业,输入每个的作业名字,到达的时间,服务的时间,根据高响应比优先算法,计算出每个作业的完成的时间,周转的时间,带权周转的时间(其中保 ...

  7. 7-3 作业调度算法--高响应比优先 (40 分)(思路+详解+vector容器做法)Come Baby!!!!!

    一:题目 输入N(N>0)个作业,输入每个作业的名字,到达时间,服务时间,按照高响应比优先算法,计算每个作业的完成时间,周转时间,带权周转时间(保留2位小数). 输入格式: 第一行输入作业数目, ...

  8. 操作系统调度算法--高响应比优先调度算法解析

    高响应比优先调度算法(Highest Response Radio Next,HRRN)是一种对CPU中央控制器响应比的分配的算法.HRRN是介于FCFS(先来先服务算法)与SJF(短作业优先算法)之 ...

  9. 高响应比优先调度算法

    任务描述 本关任务:编写一个高响应比优先调度算法解决一个实际的进程调度问题,并打印出每个进程的完成时间.周转时间和带权周转时间 相关知识 为了完成本关任务,你需要掌握:1.先来先服务调度算法,2.进程 ...

最新文章

  1. SAP PM (工厂维护)模块介绍 - SAP入门必看
  2. html不继承父级背景色,javascript – 如何获取从父元素继承的计算背景颜色样式...
  3. python pip install syntaxerror_解决pip install xxx报错SyntaxError: invalid syntax的问题
  4. 消息中间件系列四:RabbitMQ与Spring集成
  5. 在固态硬盘上安装win7后没有声音
  6. ubuntu14操作系统chrome标签和书签乱码解决
  7. Android 震动
  8. 2020 cr节目源_2020最新直播源
  9. 辞旧迎新又一年(18年年终总结)
  10. 信息安全技术 实验四 木马及远程控制技术
  11. PHP 下载保存文件到本地
  12. linux运行直播软件,在Linux下可用Wine安装和运行虎牙直播、斗鱼直播
  13. webstorm-主题和配色
  14. 上计算机课怎么备课,如何备课写教案
  15. Android 危险权限、权限组列表和所有普通权限
  16. 利用闲置的树莓派4B搭建一个NAS(二)
  17. 整理的开学需要准备的物品清单,删了怪可惜,做个备份吧
  18. 小融资 大趋势 小嗨互联网融资研究分析 20190101-20190104
  19. 伊洛纳服务器维护,《伊洛纳》【公告】伊洛纳12月23日正式服版本更新
  20. 图片怎么去底色变透明?怎么把图片变透明背景?

热门文章

  1. 二叉树前序遍历执行过程
  2. UDAL - DBProxy internal error问题解决
  3. Matlab画线性规划可行域
  4. jsp页面的iframe的用法
  5. VBS整人蓝屏代码(Windows 7 直接蓝屏,重启即可恢复,亲测有效!!)
  6. Xcode Library
  7. windous 向日葵连接 ubuntu 向日葵失败
  8. Monkey King-左偏树
  9. MyStack<T>
  10. 对技术的态度----老一辈it从业者的行业理解和对技术的激情与钻研