All pastes #1796625 Raw Edit

Grrr

public text v1 · immutable
#1796625 ·published 2010-02-14 21:25 UTC
rendered paste body
////////////////////////////////////////////////////////////
//Author: Christin Rodgers
//Date: Monday, February 10, 2010
//Overview:
//
//References:
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////

#include <iostream>
#include <queue>
#include <fstream>
#include <string>

//Stores the process ID, arrival time, and burst time of each process.
struct Task
{
	//Process ID
	int pid;

	//Arrival Time
	int aTime;

	//Burst Time
	int runTime;
};

//Function Header: FCFS
//FCFS is a function to schedule tasks in a first come first server manner.
void FCFS(Task);

//Function Header: RR
//RR is a function to schedule tasks in a round robin manner.
void RR(Task, int);

//Function Header: SJF
//SJF is a function to schedule tasks in the order of shortest job first.	
void SJF(Task);

using namespace std;

int main()
{
	//Variable Declarations
	//File pointer to open and read in the file
	ifstream inFile;
	//Temporary Task variable to store the task read in from the file
	Task temp;
	//FIFO queue for the input from the file.
	queue<Task> input;
	//Stores the input file name
	string fileName;
	//Stores the scheduling algorithm to implement
	string whichAlg;
	//Time quantum for when round robin scheduling is chosen
	int timeQuantum;

	//Get input from command line.
	cin >> fileName;
	cin >> whichAlg;
	if(whichAlg == "RR")
	{
		cin >> timeQuantum;
	}

	//Open input file
	inFile.open(fileName.c_str());
//inFile.open("temp.txt");

	//Check that file opened correctly
	if(!inFile)
	{
		cout << "Could not open the input file." << endl;
		return 1;
	}

	//Read input from file.
	while(inFile)
	{
		//Read line from input file.
		inFile >> temp.pid;		
		inFile >> temp.aTime;		
		inFile >> temp.runTime;

		//Store in input queue.
		input.push(temp);
	}

	//Close input file
	inFile.close();

	//Choose scheduling algorithm to execute.
	//If 'whichAlg' is FCFS, call FCFS function
	if(whichAlg == "FCFS")
	{
		FCFS(input);
	}
	//If 'whichAlg' is RR, call RR function
	if(whichAlg == "RR")
	{
		RR(input, timeQuantum);
	}
	//If 'whichAlg' is SJF, call SJF function
	if(whichAlg == "SJF")
	{
		SJF(input);
	}
	return 0;
}

void FCFS(Task input)
{
	//Variable Declarations
	//Stores the running task.
	Task current;
	//For-loop counter
	int i;

	cout << "Scheduling Algorithm: FCFS" << endl;
	cout << "Total " << input.size() << " tasks are read from "input.1"." 
             << "Press 'enter' to start." << endl;	

	for(i=0; i <current.runTime; i++)
	{
		cout << "<system time "<< i << "> process " << current.pid
		     << " is running" << endl;
	}
	
	return;
}

void RR(Task input, int timeQuantum)
{
	//Variable Declarations
	//Stores the running task.
	Task current;
	//For-loop counter
	int i;

	return; 
}


void SJF(Task input)
{
	//Variable Declarations
	//Stores the running task.
	Task current;
	//For-loop counter
	int i;

	return; 
}