-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ1.cpp
More file actions
71 lines (70 loc) · 1.18 KB
/
Copy pathQ1.cpp
File metadata and controls
71 lines (70 loc) · 1.18 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
#include <iostream>
using namespace std;
class Process
{
public:
string name;
int at,bt,tat,wt,rt;
void input();
void display();
};
void Process::input()
{
cout<<"\nEnter the process name, burst time and arrival time(integers)\n";
cin>>name>>bt>>at;
}
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;
double tat=0,rt=0,wt=0;
for(int i=0;i<n;i++)
{
if(p[i].at>current)
{
current=p[i].at;
i--;
continue;
}
cout<<"\n current ="<<i<<" "<<current;
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;
cout<<p[i].rt<<" "<<p[i].wt<<" "<<p[i].tat;
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;
}