62 lines
1.4 KiB
C++
62 lines
1.4 KiB
C++
#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;
|
|
}
|