updated code: someone help please!!
Code:
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
long int preList[22][2];
long int readyList[22][2];
int timeQuanta[4] = {50, 100, 250, 500};
int overheadArray[6] = {0, 5, 10, 15, 20, 25};
int main()
{
fstream inFile;
inFile.open("times.txt", ios::in);
int arrivalTime;
float timeToProcess;
int i, z = 0;
long int x = 0;
int p;
int newTime = 0;
int quantumEntered, overheadEntered;
cout<<"Please enter time quantum number 1 - 4"<<endl;
cin>>quantumEntered;
int quantum = timeQuanta[quantumEntered-1];
cout<<"Please enter overhead numer 1 - 6"<<endl;
cin>>overheadEntered;
int overhead = overheadArray[overheadEntered-1];
quantum = quantum + overhead;
//make sure file opens
if (!inFile)
{
cout<<"Error opening file."<<endl;
exit(1);
}
//open file, get stuff in there
while(!inFile.eof())
{
for(i=0; i<22; i++)
{
inFile>>arrivalTime>>timeToProcess;
preList[i][0] = arrivalTime * 1000;
preList[i][1] = timeToProcess;
cout<<preList[i][0]<<" "<<preList[i][1]<<endl;
}
}
cout<<endl<<endl;
while (x < 800000)
{
//set x%1000 into p
p = x%1000;
//if p == 0, it means x is at a number ending in 3 zeros..., so go check preList to see if process is ready to come in or not
if (p == 0)
{
//if 'arrivalTime' field in preList is equal to the current time in 'x', copy over into "readyList"
if (preList[z][0] == x)
{
//copy into readyList at arrival time
cout<<"Time is: "<<x<<endl;
readyList[z][0] = preList[z][0];
readyList[z][1] = preList[z][1];
cout<<"ready list service time: "<<readyList[z][1]<<endl;
//add processing time to arrival time to obtain and see new time
newTime = x + readyList[z][1];
cout<<"Time after run is: "<<newTime<<endl;
cout<<endl;
z++;
}
//SUPPOSED TO SEND PROCESS TO BE PROCESSED INTO PROCESSOR. IF PROCESS ARRIVES AT 30,000, AND HAS A JOB LENGTH OF 1,700, THE JOB WILL BE DONE
//AT 31,700... SUPPOSE A NEW PROCESS ARRIVES AT 35,000... THERE IS NO JOB IN THE "PROCESSOR" AT THAT TIME, SO IT IS IMMEDIATELY TAKEN TO BE PROCESSED
//THE TIME QUANTUM IS SUPPOSED TO GO AND CHECK THE "READY LIST" TO SEE IF THERE IS A JOB WAITING; IF THERE IS, THE CURRENT JOB IN THE
//PROCESSOR GETS AN ALLOCATED AMOUNT OF TIME (timeQuanta) TO PROCESS. WHEN "QUANTA" REACHES 0, THE JOB SHOULD BE SWITCHED FROM THE CURRENT JOB
//TO THE JOB WAITING IN THE READY LIST, THE NEW JOB IN GETS A TIME QUANTA OF 50, AND THE PROCESS IS REPEATED UNTIL THE ORIGINAL PROCESS IS DONE.
if (readyList[z] != 0)
{
newTime = newTime + 1;
if(quantum == 0)
{
//go check readyList, if there is something in there
//switch processes in "cpu"
quantum = timeQuanta[quantumEntered-1] + overhead;
}
cout<<"Quantum is: "<<quantum<<endl;
quantum--;
}
}
x++;
}
return 0;
}