srtf program in c 2b 2b

Solutions on MaxInterview for srtf program in c 2b 2b by the best coders in the world

showing results for - "srtf program in c 2b 2b"
Emily
04 May 2017
1#include<iostream>
2
3using namespace std;
4int main()
5{
6    int a[10],b[10],x[10];
7    int waiting[10],turnaround[10],completion[10];
8    int i,j,smallest,count=0,time,n;
9    double avg=0,tt=0,end;
10
11    cout<<"\nEnter the number of Processes: ";  //input
12    cin>>n;
13    for(i=0; i<n; i++)
14    {
15        cout<<"\nEnter arrival time of process: ";  //input
16        cin>>a[i];
17    }
18    for(i=0; i<n; i++)
19    {
20        cout<<"\nEnter burst time of process: ";  //input
21        cin>>b[i];
22    }
23    for(i=0; i<n; i++)
24        x[i]=b[i];
25
26    b[9]=9999;
27    for(time=0; count!=n; time++)
28    {
29        smallest=9;
30        for(i=0; i<n; i++)
31        {
32            if(a[i]<=time && b[i]<b[smallest] && b[i]>0 )
33                smallest=i;
34        }
35        b[smallest]--;
36
37        if(b[smallest]==0)
38        {
39            count++;
40            end=time+1;
41            completion[smallest] = end;
42            waiting[smallest] = end - a[smallest] - x[smallest];
43            turnaround[smallest] = end - a[smallest];
44        }
45    }
46    cout<<"Process"<<"\t"<< "burst-time"<<"\t"<<"arrival-time" <<"\t"<<"waiting-time" <<"\t"<<"turnaround-time"<< "\t"<<"completion-time"<<endl;
47    for(i=0; i<n; i++)
48    {
49        cout<<"p"<<i+1<<"\t\t"<<x[i]<<"\t\t"<<a[i]<<"\t\t"<<waiting[i]<<"\t\t"<<turnaround[i]<<"\t\t"<<completion[i]<<endl;
50        avg = avg + waiting[i];
51        tt = tt + turnaround[i];
52    }
53    cout<<"\n\nAverage waiting time ="<<avg/n;
54    cout<<"  Average Turnaround time ="<<tt/n<<endl;
55}
similar questions
queries leading to this page
srtf program in c 2b 2b