-
-
Save TanmayChakrabarty/8e61793ae2fbf2f2bb53e19cc3e8f6ef to your computer and use it in GitHub Desktop.
/* | |
Author: Tanmay Chakrabarty | |
Website: https://onlineclassnotes.com | |
Last Update Date: 27-06-2020 | |
Github Gists Link: https://gist.github.com/TanmayChakrabarty/8e61793ae2fbf2f2bb53e19cc3e8f6ef | |
OnlineGDB link: https://onlinegdb.com/r1UCTC4A8 | |
OnlineClassNotes Link: https://onlineclassnotes.com/2011/12/explain-and-solve-first-come-first.html | |
*/ | |
#include <iostream> | |
using namespace std; | |
int main(){ | |
int | |
t=0, | |
i, | |
j, | |
numOfProcesses = 0, | |
s=0, | |
print=0, | |
idle=0; | |
float sum=0; | |
cout << "Please enter the number of proces : "; | |
cin >> numOfProcesses; | |
int a[numOfProcesses][4]; | |
int b[numOfProcesses][5]; | |
cout<<"\n\nProcess\tArrival\tBurst\n-------\t-------\t-----\n"; | |
for(i = 0; i < numOfProcesses; i++){ | |
for(j = 0; j < 3; j++){ | |
cin >> a[i][j]; | |
} | |
a[i][3] = a[i][2]; | |
} | |
cout << "\n\nTime-Line is as follows (Verticle View)....\n\n"; | |
/**************************Processing Starts Here*************/ | |
for(i = 0, t = a[0][1]; i < numOfProcesses; i++){ | |
while(a[i][2] != 0){ | |
if(t >= a[i][1]){ | |
if(print == 0) | |
printf("%5d-----------\n |p-%-4d|\n", t, a[i][0]); | |
print = 1; | |
idle = 0; | |
a[i][2]--; | |
} | |
else{ | |
if(idle == 0){ | |
printf("%5d-----------\n |Idle |\n", t); | |
idle = 1; | |
} | |
} | |
t++; | |
} | |
print = 0; | |
b[s][0] = a[i][0]; | |
b[s][1] = a[i][1]; | |
b[s][2] = t; | |
b[s][3] = a[i][3]; | |
b[s][4] = ((t - a[i][1]) - a[i][3]); | |
sum += b[s][4]; | |
s++; | |
} | |
printf("%5d-----------\n", t); | |
/**************************Processing Ends Here*************/ | |
cout << endl << endl; | |
cout << "Table of processes with completion record as they were completed\n\n"; | |
cout << "\n\nProcess\tArrival\tFinish\tTotal\tWait\n------------------------------------\n"; | |
for(i = 0; i < s; i++) | |
cout << b[i][0] << "\t" << b[i][1] << "\t" << (b[i][2] - 1) << "\t" << b[i][3] << "\t" << b[i][4] << "\n"; | |
cout << "\n\nAvg. Wait time = " << (sum/numOfProcesses) << endl << endl; | |
cout << "__________________________________________________________\nProgrammed by : Tanmay Chakrabarty, onlineclassnotes.com.\n\n"; | |
return 0; | |
} |
y ur code shows error.....?
that's hilarious code
I am sorry.
This code and other similar gists were written back in 2008. Its nearly 10 years since I ever ran these codes, I can't even remember the compiler I used for compiling these codes.
After your comment, I searched and found some converters to convert old c++ codes to latest c++17 codes and others. I will try those and will submit the converted code here.
Thank you for trying though.
Hello @suborna020, I managed to alter the code so that it can compile. I tested the current altered code at this URL https://www.onlinegdb.com/online_c++_compiler
using C++, C++14, C++17
It ran successfully.
@suborna020 you are welcome.
can i know the name or function for every variable for better understanding of the code ?
Read explanation on First Come First Served at
https://www.onlineclassnotes.com/2011/12/explain-and-solve-first-come-first.html