Write a program to implement FCFS CPU scheduling algorithm
#include <iostream>
using namespace std;
// create structure
struct process{
int pid;
int arrive_time;
int burst_time;
int completion_time;
int turn_around_time;
int waiting_time;
};
//create function to calculate completion waiting_time
void findCompletionTime(process proc[],int n){
proc[0].completion_time=proc[0].burst_time;
for(int i=1;i<n;i++){
proc[i].completion_time=proc[i-1].completion_time+proc[i].burst_time;
}
// create function to calculate turn_around_time
void findTurnAroundTime(process proc[],int n){
for(int i=0;i<n;i++){
proc[i].turn_around_time = proc[i].completion_time-proc[i].arrive_time;
// create function to calculate waiting_time
void findWaitingTime(process proc[],int n){
proc[0].waiting_time=0;
for(int i=1;i<n;i++){
proc[i].waiting_time = proc[i].turn_around_time-proc[i].burst_time;
// create a function for call the functions
void findFCFS(process proc[],int n){
findCompletionTime(proc,n);
findTurnAroundTime(proc,n);
findWaitingTime(proc,n);
// create a function for print the value
void printFCFS(process proc[],int n){
cout<<"FCFS Scheduling :" <<endl;
cout<<"PID\t Arrive Time\t Burst Time\t Completion Time\t TurnAroundTime\t
WaitingTime"<<endl;
for(int i=0; i<n;i++){
cout<<proc[i].pid<<"\t\t"<<proc[i].arrive_time<<"\t\t"<<proc[i].burst_time<<"\t\t"<<
proc[i].completion_time<<"\t\t"<<proc[i].turn_around_time<<"\t\t"<<proc[i].waiting_time<<
endl;
int main()
{
int n=5; // declare array size
// create multidimensional array
process proc[n] = {{1,0,5},{2,1,3,},{3,2,2},{4,3,4},{5,4,1}};
findFCFS(proc , n); //call function
printFCFS (proc , n); // call function
return 0;