Last active
November 20, 2021 23:02
-
-
Save TanmayChakrabarty/8e61793ae2fbf2f2bb53e19cc3e8f6ef to your computer and use it in GitHub Desktop.
C++ Program (Source Code) for First Come First Served (FCFS) CPU Scheduling Algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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; | |
} |
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.
Tnx a lot.... Bt Im sry if i commnted like a rude
…On Tue, 27 Aug 2019, 2:43 am TanmayChakrabarty, ***@***.***> wrote:
Hello @suborna020 <https://github.com/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.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://gist.github.com/8e61793ae2fbf2f2bb53e19cc3e8f6ef?email_source=notifications&email_token=AG4V6CZSGVGOTI6Y762M4ATQGQ57NA5CNFSM4IPTAJM2YY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFXUN4#gistcomment-3008734>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AG4V6C5ONPQ7JAETSLDP2A3QGQ57NANCNFSM4IPTAJMQ>
.
@suborna020 you are welcome.
can i know the name or function for every variable for better understanding of the code ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.