代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
c++ 作业调度模拟
作者:
Dezai.CN
/ 发布于
2013/6/20
/
449
#include<stdio.h> #include<iostream.h> #include<iomanip.h> #include<string.h> //本程序包括:FIFO,运算时间短的作业优先,优先数调度算法,响应比最高者优先调度算法 const int MAXJOB = 50; //定义最大作业 //定义数据结构体 typedef struct node { 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; } job; job jobs[MAXJOB]; int quantity; //初始化函数 void initial() { int i; for(i = 0; i < MAXJOB; i++) { jobs[i].number = 0; jobs[i].reach_time = 0; jobs[i].reach_hour = 0; jobs[i].reach_minite = 0; jobs[i].privilege = 0; jobs[i].excellent = 0; jobs[i].start_time = 0; jobs[i].wait_time = 0; jobs[i].visited = 0; } quantity = 0; } //重置作业数据函数 void reset() { int i; for(i = 0; i < MAXJOB; i++) { jobs[i].start_time = 0; jobs[i].wait_time = 0; jobs[i].visited = 0; } } //读入作业数据函数 void readData() { FILE *fp; char fname[20]; int i; cout << "请输入作业数据文件名:"; strcpy(fname, "8job.txt"); cin >> fname; if((fp = fopen(fname, "r")) == NULL) { cout << "错误,文件打不开,请检查文件名:)" << endl; } else { while(!feof(fp)) { fscanf(fp, "%d %d %d %d", &jobs[quantity].number, &jobs[quantity].reach_time, &jobs[quantity].need_time, &jo bs[quantity].privilege); jobs[quantity].reach_hour = jobs[quantity].reach_time / 100; jobs[quantity].reach_minite = jobs[quantity].reach_time % 100; quantity++; } //输出初始作业数据 cout << "输出初始作业数据" << endl; cout << "---------------------------------------------------------------" << endl; cout.setf(2); cout << setw(10) << "作业号" << setw(12) << "到达时间" << setw(14) << "所需时间(分)" << setw(14) << "优先级(0>1)" << endl; for(i = 0; i < quantity; i++) { cout << setw(10) << jobs[i].number << setw(12) << jobs[i].reach_time << setw(14) << jobs[i].need_time << setw(14) << jobs[i].privil ege << endl; } } } //FIFO算法 void FIFO() { int i; int current_hour; int current_minute; int total_time = 0; //输出作业流 cout << endl; cout << endl << "FIFO算法作业流" << endl; cout << "---------------------------------------------------------------" << endl; cout.setf(2); cout << setw(10) << "作业号" << setw(12) << "到达时间" << setw(12) << "开始时间" << setw(14) << "周转时间(分)" << endl; current_hour = jobs[0].reach_hour; current_minute = jobs[0].reach_minite; for(i = 0; i < quantity; i++) { jobs[i].start_time = current_hour * 100 + current_minute; jobs[i].wait_time = (current_hour - jobs[i].reach_hour) * 60 + (current_minute - jobs[i].reach_minite) + jobs[i ].need_time; cout << setw(10) << jobs[i].number << setw(12) << jobs[i].reach_time << setw(12) << jobs[i].start_time << setw(14) << jobs[i].wait_ time << endl; current_hour = current_hour + (jobs[i].need_time + current_minute) / 60; current_minute = (jobs[i].need_time + current_minute) % 60; total_time += jobs[i].wait_time; } cout << endl << "总周转时间:" << total_time << " 平均周转时间:" << total_time / quantity << endl; } //运算时间短的作业优先算法 void shorter() { int i, j, p; int current_hour; int current_minute; int current_need_time; int total_time = 0; //输出作业流 cout << endl; cout << endl << "时间短作业优先算法作业流(开始调度时刻为最后一个作业到达系统的时间)" << endl; cout << "------------------------------------------------------------------------" << endl; cout.setf(2); cout << setw(10) << "作业号" << setw(12) << "到达时间" << setw(14) << "所需时间(分)" << setw(12) << "开始时间" << setw(14) << "周转时间(分)" << endl; current_hour = jobs[quantity - 1].reach_hour; current_minute = jobs[quantity - 1].reach_minite; for(i = 0; i < quantity; i++) { current_need_time = 30000; for(j = 0; j < quantity; j++) { if((jobs[j].visited == 0) && (jobs[j].need_time < current_need_time)) { p = j; current_need_time = jobs[j].need_time; } } jobs[p].start_time = current_hour * 100 + current_minute; jobs[p].wait_time = (current_hour - jobs[p].reach_hour) * 60 + (current_minute - jobs[p].reach_minite) + jobs[p ].need_time; cout << setw(10) << jobs[p].number << setw(12) << jobs[p].reach_time << setw(14) << jobs[p].need_time << setw(12) << jobs[p].start_ time << setw(14) << jobs[p].wait_time << endl; current_hour = current_hour + (jobs[p].need_time + current_minute) / 60; current_minute = (jobs[p].need_time + current_minute) % 60; jobs[p].visited = 1; total_time += jobs[p].wait_time; } cout << endl << "总周转时间:" << total_time << " 平均周转时间:" << total_time / quantity << endl; } //优先数调度算法 void privilege() { int i, j, p; int current_hour; int current_minute; int current_privilege; int total_time = 0; //输出作业流 cout << endl; cout << endl << "优先数调度算法作业流(开始调度时刻为最后一个作业到达系统的时间)" << endl; cout << "------------------------------------------------------------------------" << endl; cout.setf(2); cout << setw(10) << "作业号" << setw(12) << "到达时间" << setw(14) << "优先级(0>1)" << setw(12) << "开始时间" << setw(14) << "周转时间(分)" << endl; current_hour = jobs[quantity - 1].reach_hour; current_minute = jobs[quantity - 1].reach_minite; for(i = 0; i < quantity; i++) { current_privilege = 30000; for(j = 0; j < quantity; j++) { if((jobs[j].visited == 0) && (jobs[j].privilege < current_privilege)) { p = j; current_privilege = jobs[j].privilege; } } jobs[p].start_time = current_hour * 100 + current_minute; jobs[p].wait_time = (current_hour - jobs[p].reach_hour) * 60 + (current_minute - jobs[p].reach_minite) + jobs[p ].need_time; cout << setw(10) << jobs[p].number << setw(12) << jobs[p].reach_time << setw(14) << jobs[p].privilege << setw(12) << jobs[p].start_ time << setw(14) << jobs[p].wait_time << endl; current_hour = current_hour + (jobs[p].need_time + current_minute) / 60; current_minute = (jobs[p].need_time + current_minute) % 60; jobs[p].visited = 1; total_time += jobs[p].wait_time; } cout << endl << "总周转时间:" << total_time << " 平均周转时间:" << total_time / quantity << endl; } //响应比最高者优先调度算法 void excellent() { int i, j, p; int current_hour; int current_minute; float current_excellent; int total_time = 0; //输出作业流 cout << endl; cout << endl << "响应比高者优先调度算法作业流(开始调度时刻为最后一个作业到达系统的时间)" << endl; cout << "------------------------------------------------------------------------" << endl; cout.setf(2); cout << setw(10) << "作业号" << setw(12) << "到达时间" << setw(12) << "开始时间" << setw(14) << "周转时间(分)" << endl; current_hour = jobs[quantity - 1].reach_hour; current_minute = jobs[quantity - 1].reach_minite; for(i = 0; i < quantity; i++) { current_excellent = -1; for(j = 0; j < quantity; j++) { if(jobs[j].visited == 0) { jobs[j].wait_time = (current_hour - jobs[j].reach_hour) * 60 + (current_minute - jobs[j].reach_minite); jobs[j].excellent = (float)(jobs[j].wait_time / jobs[j].need_time); } } for(j = 0; j < quantity; j++) { if((jobs[j].visited == 0) && (jobs[j].excellent > current_excellent)) { p = j; current_excellent = jobs[j].excellent; } } jobs[p].start_time = current_hour * 100 + current_minute; jobs[p].wait_time = (current_hour - jobs[p].reach_hour) * 60 + (current_minute - jobs[p].reach_minite) + jobs[p ].need_time; cout << setw(10) << jobs[p].number << setw(12) << jobs[p].reach_time << setw(12) << jobs[p].start_time << setw(14) << jobs[p].wait_ time << endl; current_hour = current_hour + (jobs[p].need_time + current_minute) / 60; current_minute = (jobs[p].need_time + current_minute) % 60; jobs[p].visited = 1; total_time += jobs[p].wait_time; } cout << endl << "总周转时间:" << total_time << " 平均周转时间:" << total_time / quantity << endl; } //显示版权信息函数 void version() { cout << endl << endl; cout << " ┏━━━━━━━━━━━━━━━━━━━━━━━┓" << endl; cout << " ┃ 作业调度模拟系统 ┃" << endl; cout << " ┠───────────────────────┨" << endl; cout << " ┃ (c)All Right Reserved Neo ┃" << endl; cout << " ┃ sony006@163.com ┃" << endl; cout << " ┃ version 2004 build 1122 ┃" << endl; cout << " ┗━━━━━━━━━━━━━━━━━━━━━━━┛" << endl; cout << endl << endl; } void main() { version(); initial(); readData(); FIFO(); shorter(); reset(); privilege(); reset(); excellent(); }
试试其它关键字
作业调度
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3