From ba4a29ebf44295dc76dc1c7e94da3c52083ea3cc Mon Sep 17 00:00:00 2001 From: Kshitij Date: Tue, 30 Jul 2024 11:59:54 +0530 Subject: [PATCH] added waiting, turnaround and response time in FCFS and SJF code. Thanks to Ayush Kalaskar for their contribution. --- .../Assignment - 5/FCFS (Non-Preemptive).cpp | 33 +++++++++++--- .../Assignment - 5/SJF (Preemptive).cpp | 44 ++++++++++++++----- 2 files changed, 59 insertions(+), 18 deletions(-) mode change 100644 => 100755 Codes/Group B/Assignment - 5/FCFS (Non-Preemptive).cpp mode change 100644 => 100755 Codes/Group B/Assignment - 5/SJF (Preemptive).cpp diff --git a/Codes/Group B/Assignment - 5/FCFS (Non-Preemptive).cpp b/Codes/Group B/Assignment - 5/FCFS (Non-Preemptive).cpp old mode 100644 new mode 100755 index d4cc495..9ceb16f --- a/Codes/Group B/Assignment - 5/FCFS (Non-Preemptive).cpp +++ b/Codes/Group B/Assignment - 5/FCFS (Non-Preemptive).cpp @@ -1,12 +1,14 @@ #include using namespace std; -struct fcfs{ - int burst, arrival, id, completion; +struct fcfs +{ + int burst, arrival, id, completion, waiting, turnaround, response; }; fcfs meh[30]; -class FCFS{ +class FCFS +{ public: int n; void fcfsIn(){ @@ -24,6 +26,7 @@ public: cout<<"P"< +#include // for INT_MAX using namespace std; struct sjf{ - int burst, arrival, id, completion; + int burst, arrival, id, completion, waiting, turnaround, response; bool active; }; + sjf meh[30]; class lesgo{ @@ -14,7 +16,7 @@ public: void sjfIn(){ cout<<"\nEnter number of processes: "; cin>>n; - for(int i = 0; i < n; i++){ + for(int i = 1; i <= n; i++){ cout<<"\nEnter arrival time of P"<>meh[i].arrival; cout<<"\nEnter burst time of P"< 0){ if(meh[i].burst < burst1){ burst1 = meh[i].burst; @@ -44,11 +46,19 @@ public: } } if(iddd != -1){ + // Mark the process as active + if(!meh[iddd].active) { + meh[iddd].response = k - meh[iddd].arrival; + meh[iddd].active = true; + } + cout<<"P"<