-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ3.cpp
More file actions
81 lines (79 loc) · 1.27 KB
/
Copy pathQ3.cpp
File metadata and controls
81 lines (79 loc) · 1.27 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
using namespace std;
class Process
{
public:
string name;
int at,bt,tat,wt,rt,prio;
void input();
void display();
};
void Process::input()
{
cout<<"\nEnter the process name, burst time and arrival time and priority(integers)\n";
cin>>name>>bt>>at>>prio;
}
void Process::display()
{
cout<<endl<<name<<"\t"<<tat<<"\t"<<wt<<"\t"<<rt<<"\n";
}
int main()
{
int flag;
Process p[20];
int n=0;
do
{
p[n++].input();
cout<<"\nDo you want to add another process?(0 to stop)";
cin>>flag;
}while(flag);
Process p1;
for(int i=0;i<n;i++)
{
for(int j=0;j<n-i-1;j++)
{
if(p[j].at>p[j+1].at)
{
p1=p[j];
p[j]=p[j+1];
p[j+1]=p1;
}
}
}
int current=0,min;
double tat=0,rt=0,wt=0;
for(int i=0;i<n;i++)
{
min=i;
if(p[i].at>current)
{
current=p[i].at;
i--;
continue;
}
for(int j=i+1;j<n&&p[j].at<=current;j++)
{
if(p[min].prio<p[j].prio)
{
min=j;
}
}
p1=p[i];
p[i]=p[min];
p[min]=p1;
p[i].rt=current-p[i].at;
p[i].wt=current-p[i].at;
p[i].tat=current+p[i].bt-p[i].at;
current+=p[i].bt;
tat+=p[i].tat;
rt+=p[i].rt;
wt+=p[i].wt;
}
cout<<"\nName\tTAT\tWT\tRT\n";
for(int i=0;i<n;i++)
{
p[i].display();
}
cout<<"\nAverage Times:-\nTAT ="<<tat/n<<"\nWT ="<<wt/n<<"\nRT ="<<rt/n<<endl;
}