2
1

added fcfs code

This commit is contained in:
Tanmay 2024-07-28 12:32:06 +05:30
parent 824a7ef5fd
commit 3e3c0978b9
3 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,61 @@
#include<iostream>
using namespace std;
struct fcfs{
int burst, arrival, id, completion;
};
fcfs meh[30];
class FCFS{
public:
int n;
void fcfsIn(){
cout<<"\nEnter number of processes: ";
cin>>n;
for(int i = 0; i < n; i++){
cout<<"\nEnter arrival time of P"<<i<<": ";
cin>>meh[i].arrival;
cout<<"\nEnter burst time of P"<<i<<": ";
cin>>meh[i].burst;
meh[i].id = i;
}
cout<<"\n | Arrival | Burst\n";
for(int j = 0; j < n; j++) {
cout<<"P"<<j<<"| "<<meh[j].arrival<<" | "<<meh[j].burst<<"\n";
}
}
void process() {
cout<<"\nSequence of processes is: ";
int currentTime = 0;
for(int i = 0; i < n; i++){
if(currentTime < meh[i].arrival){
while(currentTime < meh[i].arrival){
cout<<" NULL ";
currentTime++;
}
}
cout<<"P"<<meh[i].id<<" ";
currentTime += meh[i].burst;
meh[i].completion = currentTime;
}
}
void completion()
{
cout<<"\n\n | Completion time\n";
for(int j = 0; j < n; j++) {
cout<<"P"<<j<<"| "<<meh[j].completion<<"\n";
}
}
};
int main()
{
FCFS obj;
obj.fcfsIn();
obj.process();
obj.completion();
return 0;
}

View File

@ -2,4 +2,5 @@
##### Group B ##### Group B
5. [CPU Scheduling Algorithms: FCFS, SJF (Preemptive), Priority (Non-Preemptive) and Round Robin (Preemptive)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20B/Assignment%20-%205) 5. [CPU Scheduling Algorithms: FCFS, SJF (Preemptive), Priority (Non-Preemptive) and Round Robin (Preemptive)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20B/Assignment%20-%205)
- [FCFS (Non-Preemptive)]()
- [SJF (Preemptive)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20B/Assignment%20-%205/SJF%20%28Premptive%29.cpp) - [SJF (Preemptive)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20B/Assignment%20-%205/SJF%20%28Premptive%29.cpp)