2
1
SystemsProgrammingAndOperat.../Codes/Group B/Assignment - 5/FCFS (Non-Preemptive).cpp

62 lines
1.4 KiB
C++
Raw Normal View History

2024-07-27 11:18:03 +05:30
#include<iostream>
using namespace std;
2024-07-28 12:32:06 +05:30
struct fcfs{
2024-07-27 11:46:42 +05:30
int burst, arrival, id, completion;
2024-07-27 11:18:03 +05:30
};
2024-07-28 12:32:06 +05:30
fcfs meh[30];
2024-07-27 11:18:03 +05:30
2024-07-28 12:32:06 +05:30
class FCFS{
2024-07-27 11:18:03 +05:30
public:
int n;
2024-07-28 12:32:06 +05:30
void fcfsIn(){
2024-07-27 11:18:03 +05:30
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";
}
}
2024-07-28 12:32:06 +05:30
void process() {
2024-07-27 11:18:03 +05:30
cout<<"\nSequence of processes is: ";
2024-07-28 12:32:06 +05:30
int currentTime = 0;
for(int i = 0; i < n; i++){
if(currentTime < meh[i].arrival){
while(currentTime < meh[i].arrival){
cout<<" NULL ";
currentTime++;
2024-07-27 11:18:03 +05:30
}
}
2024-07-28 12:32:06 +05:30
cout<<"P"<<meh[i].id<<" ";
currentTime += meh[i].burst;
meh[i].completion = currentTime;
2024-07-27 11:18:03 +05:30
}
}
2024-07-27 11:46:42 +05:30
void completion()
{
cout<<"\n\n | Completion time\n";
for(int j = 0; j < n; j++) {
cout<<"P"<<j<<"| "<<meh[j].completion<<"\n";
}
}
2024-07-27 11:18:03 +05:30
};
2024-07-28 12:32:06 +05:30
int main()
{
FCFS obj;
obj.fcfsIn();
obj.process();
2024-07-27 11:46:42 +05:30
obj.completion();
2024-07-27 11:18:03 +05:30
return 0;
}