1、1作业调度一、 实验名称作业调度算法二、实验目标在单道环境下编写作业调度的模拟程序,以加深对作业调度的理解。单道环境的特点使被调度的作业占有所有的资源。实现的算法有先来先服务,最短作业优先,最高响应比三种作业调度算法。三、实验环境要求:1.PC 机。2.Windows;3.CodeBlocks 四、实验基本原理1.本实验设计一个可指定作业个数的作业调度系统。可以输出先来先服务,最短作业优先,最高响应比三种作业调度算法的结果。2.先来先服务就是按照各个作业进入系统的自然次序进行调度。最短作业优先就是优先调度并且处理短作业。最高响应比优先就是根据在程序运行过程中的最高响应比对应的作业先进行调度处理
2、。3.在设计程序过程中,将 time 相关的内容封装到类中,重载了加减乘除和输入输出以及比较运算符,方便 12:00 这种形式的数据的加减乘除运算和比较运算, 五、数据结构设计1.时间类2class time public:time(int x = 0, int y = 0) time:hour = x;time:minute = y;timethis-minute=t1.minute;return *this;time operator + (time t2)int minutes,hours;minutes = (minute + t2.minute) % 60;hours=hour+t2
3、.hour+ (minute + t2.minute) /60;return time(hours,minutes);time operator -(time t2)int minutes,hours;minutes =minute - t2.minute;if (minute(istream scanf(“%d:%d“, t1.hour = h;t1.minute = m;return in;public:int hour;4int minute; 2.作业内容typedef struct JOBchar name20;/Job nametime in_time;int run_time;t
4、ime st_time;time end_time;int round_time;/周转时间int wait_time;double rounds_time;/带权周转double reson_radio;/响应比job;六、流程图5七、源代码#include#include#include#includeusing namespace std;class time public:time(int x = 0, int y = 0) time:hour = x;time:minute = y;timethis-minute=t1.minute;return *this;time operato
5、r + (time t2)6int minutes,hours;minutes = (minute + t2.minute) % 60;hours=hour+t2.hour+ (minute + t2.minute) /60;return time(hours,minutes);time operator -(time t2)int minutes,hours;minutes =minute - t2.minute;if (minute(istream scanf(“%d:%d“, t1.hour = h;t1.minute = m;return in;public:int hour;7int
6、 minute;typedef struct JOBchar name20;/Job nametime in_time;int run_time;time st_time;time end_time;int round_time;/周转时间int wait_time;double rounds_time;/带权周转double reson_radio;/响应比job;double sum_time;/全部作业周转时间和double sums_time;/全部作业带权周转时间和int n;/job counts/重载 maxtime maxn(time t1, time t2) if(t1.ho
7、urt2.hour)return t1;else if(t1.hour=t2.hour)if (t1.minute t2.hour) return t1;return t2;/eg: 120 转化成 2:0time m_exchange_h(int run_time) time run;run.hour = run_time / 60;run.minute = run_time % 60;return run;/eg: 2:0 转化成 120int h_exchange_m(time t1) return t1.hour * 60 + t1.minute;/先来先服务;8void job_in
8、put(job *x) cout radio_max) temp = j;radio_max=xj.reson_radio;if (temp != -1) xtemp.st_time = xe.end_time;e = temp;else e+;xe.st_time = xe.in_time;xe.end_time = xe.st_time + m_exchange_h(xe.run_time);xe.round_time = h_exchange_m(xe.end_time - xe.in_time);xe.rounds_time = xe.round_time*1.0 / xe.run_time;sum_time += xe.round_time;sums_time += xe.rounds_time;flage = 1;i+;cout n;coutendl;