FCFS
FCFS
#include <vector>
#include <algorithm>
struct Process {
int pid;
int arrival_time;
int burst_time;
int waiting_time;
int turnaround_time;
int completion_time;
};
cout << "\nAverage Waiting Time: " << (float)total_waiting_time / processes.size() << "\n";
cout << "Average Turnaround Time: " << (float)total_turnaround_time / processes.size() << "\n";
}
current_time += p.burst_time;
cout << "\t" << current_time;
}
cout << "\n";
}
int main() {
int n;
cout << "Enter the number of processes: ";
cin >> n;
vector<Process> processes(n);
calculateTimes(processes);
calculateTurnaroundTime(processes);
displayResults(processes);
return 0;
}
//output:
//Enter the number of processes: 5
//Enter arrival time for process P1: 0
//Enter burst time for process P1: 4
//Enter arrival time for process P2: 1
//Enter burst time for process P2: 3
//Enter arrival time for process P3: 2
//Enter burst time for process P3: 1
//Enter arrival time for process P4: 3
//Enter burst time for process P4: 2
//Enter arrival time for process P5: 4
//Enter burst time for process P5: 5
//Process Arrival Time Burst Time Waiting Time Turnaround Time Completion Time
//P1 0 4 0 4 4
//P2 1 3 3 6 7
//P3 2 1 5 6 8
//P4 3 2 5 7 10
//P5 4 5 6 11 15
//
//Average Waiting Time: 3.8
//Average Turnaround Time: 6.8
//
//Gantt Chart:
//| P1 | P2 | P3 | P4 | P5 |
//0 4 7 8 10 15
//
//--------------------------------
//Process exited after 31.11 seconds with return value 0
//Press any key to continue . . .