-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProcess_scheduling_OS.cpp
More file actions
66 lines (55 loc) · 1.34 KB
/
Copy pathProcess_scheduling_OS.cpp
File metadata and controls
66 lines (55 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<bits/stdc++.h>
using namespace std;
struct event
{
int arrival_time;
int burst_time;
int completion_time;
int index;
int system_mila;
};
bool comp(event a,event b)
{
return a.burst_time<b.burst_time;
}
event all[100];
struct result
{
int waiting_time;
int turn_around;
};
result ans[100];
int main()
{
int n,i,j;
cout<<"Enter no of processes:\n";
cin>>n;
cout<<"Enter arrival and burst time of all the processes: \n";
for(i=0;i<n;i++)
{
cout<<"Process "<<i+1<<": ";
cin>>all[i].arrival_time;
cin>>all[i].burst_time;
all[i].index = i;
}
sort(all, all+n, comp);
int time=all[0].arrival_time;
for(i=0;i<n;i++)
{
all[i].system_mila = time;
time = time + all[i].burst_time;
all[i].completion_time = time;
}
for(i=0;i<n;i++)
{
ans[all[i].index].turn_around = all[i].completion_time - all[i].arrival_time;
ans[all[i].index].waiting_time = ans[all[i].index].turn_around - all[i].burst_time;
}
cout<<"\n\nResults:\nProcess\t\tTurn Around Time\t Waiting Time\n";
cout<<fixed<<showpoint<<setprecision(2);
for(i=0;i<n;i++)
{
cout<<i+1<<fixed<<showpoint<<setprecision(2)<<"\t\t\t "<<(double)ans[i].turn_around<<"\t\t\t"<<(double)ans[i].waiting_time<<endl;
}
return 0;
}