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