操作系统进程调度算法模拟__MFC实现.doc
文本预览下载声明
范文 范例 指导 学习
word版本整理分享
#include windows.h
#include windowsx.h
#include tchar.h
#include strsafe.h
#include resource.h
#pragma warning(disable:4312)
#pragma warning(disable:4244)
#define EDITLEN 20
#define RR 2 // 时间片
#define chHANDLE_DLGMSG(hWnd, message, fn) case (message): return (SetDlgMsgResult(hWnd, uMsg, HANDLE_##message((hWnd), (wParam), (lParam), (fn))))
struct ProcInfo {
int procID; // 进程ID
float arriveT; // 达到时间
float serverT; // 服务时间
float remainT; // 剩余运行时间
float lastrunT; // 上次运行时间
float runT; // 运行时间总和
float priority; // 优先级,高响应比优先调度算法时初始为1,其他算法未用到,初始为0
struct ProcInfo *next; // 下一结点
} *startProc,*endProc;
HWND hWnd;
/*
检查6个进程的到达时间和服务时间是否已经全部输入
已经全部输入返回TRUE,否则返回FALSE
*/
bool CheckEdits()
{
wchar_t str[EDITLEN];
for (int i=IDC_A1;i=IDC_F1;i+=5) {
GetDlgItemText(hWnd,i,str,EDITLEN);
if (lstrcmp(str,_T(\0)) == 0)
return false;
GetDlgItemText(hWnd,i+1,str,EDITLEN);
if (lstrcmp(str,_T(\0)) == 0 )
return false;
}
return true;
}
/*
计算平均周转时间和平均带权周转时间,并显示
*/
void ShowEdits()
{
float zzsj=0,pjzz=0;
wchar_t str[10];
for (int i=IDC_A4;i=IDC_F4;i+=5) {
GetDlgItemText(hWnd,i,str,10);
zzsj += _wtof(str);
GetDlgItemText(hWnd,i+1,str,10);
pjzz += _wtof(str);
}
StringCchPrintf(str,10,_T(%f),zzsj/6);
SetDlgItemText(hWnd,IDC_TIME1,str);
StringCchPrintf(str,10,_T(%f),pjzz/6);
SetDlgItemText(hWnd,IDC_TIME2,str);
}
/*
清除所有编辑框的内容
*/
void ClearEdits()
{
for (int i=IDC_A1;iIDC_TIME2+1;i++ ) {
SetWindowText(GetDlgItem(hWnd,i),_T());
}
}
/*
在链表尾部插入node结点
*/
void InsertNode(ProcInfo* node)
{
if (startProc == NULL) {
startProc = endProc = node;
} else {
endProc-next = node;
endProc = node;
if (startProc-next == NULL) {
startProc-next = endProc;
}
}
}
/*
移除链表头结点
*/
void RemoveNode()
{
if (startProc != NULL) {
float finishT;
wchar_t str[10];
ProcInfo *tmp = startProc;
if (startProc-next != N
显示全部