单处理器进程调度算法模拟,FCFS,RR(q=1),SPN,SRT,HRRN1

oslab4.h

#ifndef OSLAB4_H
#define OSLAB4_H

#include<iostream>
using namespace std;

class SelectionFunction
{
public:
	SelectionFunction();
	~SelectionFunction();
	void InputProcess();
	void FCFS();
	void RR();
	void SPN();
	void SRT();
	void HRRN(); 

private:

	
	void OutputInformation( char * name);
	int FindTheShortestProcess( int runTime);
	int FindHightestRate (int runTime);
	int FindShortestRemain(int runTime);
	int FindNextExcuteProcess( int currentProcess, int runTime);
	void SetProInformation(int currentProcess , int runTime);

	void ClearProcessInformation();
	//inputed processes information
	struct Process
	{
		char ID;
		unsigned int arrivedTime;
		unsigned int serverTime;
		
	};

	//the calculated information of process 
	struct ProcessInformation
	{
		unsigned int finishTime;
		unsigned int turnaroundTime;
		double rate;
		bool isExcuted;
		bool isFirst;
		int remainTime;
	};

	int length;
	struct Process *process;
	struct ProcessInformation *proInformation;

	void put();
};

#endif

oslab4.cpp

#include"oslab4.h"
SelectionFunction::SelectionFunction()
{
	process = NULL;
	proInformation = NULL;
	length = 0;
}

SelectionFunction::~SelectionFunction()
{
	delete [] process;
	process = NULL;
	delete [] proInformation;
	proInformation = NULL;

}

void SelectionFunction::InputProcess()
{

	cout<<"Input the numbers of process:";
	cin>>length;

	if(length<1)
	{
		cout<<"The numbers of process can't less 1"<<endl;
		return ;
	}

	//dynamic new an array to store process information
	process = new struct Process[length];
	if(process == NULL)
	{
		cout<<"New function error! Quit!"<<endl;
		return ;
	}
	proInformation = new struct ProcessInformation[length];
	if (proInformation == NULL)
	{
		cout<<"New function error! Quit!"<<endl;
		return ;
	}
	ClearProcessInformation();
	
	cout<<"Two nonnagetive umbers for process arrive time and sever time:"<<endl;
	for (int i = 0; i < length; i++)
	{
		cin>>process[i].arrivedTime>>process[i].serverTime;
		process[i].ID = 'A'+i;
		if (process[i].serverTime == 0)
		{
			cout<<"Server time can't be zero!"<<endl;
			return ;
		}
	}


}

void SelectionFunction::FCFS()
{
	int runTime = 0;
	for (int i = 0; i < length; i++)
	{
		if (process[i].arrivedTime>runTi
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值