,   CyberForum.ru

Round Robin - C++

 
:  :  - 9,   - 4.78
NewDay
0 / 0 / 0
: 20.09.2012
: 10
23.09.2012, 11:22     Round Robin #1
?
C++
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
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
 
void main ()
{
    int n,y,i,g=0,k=0,j,u;
    int bur[100],wait[100], turnar[100];
    int sum=0;
    double avewait=0.0,aveturn=0.0;
 
 
    cout<<"Number of processes= "<<endl;
    cin>>y;
    n=y*2;
 
    for (i=0;i<n/2;i++)
    {   
        cout<<"Enter Burst time= "<<endl;
        cin>>bur[i];
        g++;
 
    }
    for (i=n/2;i<n;i++)
    {   
        cout<<"Enter Second Burst time= "<<endl;
        cin>>bur[i];
        k++;
    }
    system("CLS");
 
    for (i=0;i<n;i++)
    {
        sum=0;
        for (j=0;j<i;j++)
            sum=sum+bur[j];
        wait[i]=sum;
    }
 
    for (i=0;i<n;i++)
    {
        turnar[i]=wait[i]+bur[i];
    }
    for (i=0;i<n;i++)
    {
        avewait+=wait[i];
        aveturn+=turnar[i];
    }
    
    avewait/=n;
    aveturn/=n;
 
    cout<<endl;
 
    cout<<"PROCESS ID     BURST TIME      WAIT TIME       TURNAROUND TIME ";
    
    
    cout<<endl;
    cout<<endl;
    for (i=0;i<n/2;i++)
    {
        cout<<i+1<<"\t\t"<<bur[i]<<"\t\t"<<wait[i]<<"\t\t"<<turnar[i];
        cout<<endl;
    }
    cout<<endl;
        
    for (i=n/2;i<n;i++)
    {
            
        cout<<i+1<<"\t\t"<<bur[i]<<"\t\t"<<wait[i]<<"\t\t"<<turnar[i];
        cout<<endl;
    }
    cout<<"***************************************************************";
    cout<<endl;
    cout<<endl;
    cout<<"Average Wait Time="<<avewait<<endl;
    cout<<"Average Turnaround Time="<<aveturn<<endl;
    getch();
 
}
Similar
41792 / 34177 / 6122
: 12.04.2006
: 57,940
23.09.2012, 11:22     Round Robin
:

Round-robin Delphi
Java SE round robin 20
C++ round C++
C++ [C++] round()
Round Robin ( ) C++
round(i) C++
round myround C++
C++ Round Floor ?



:
.
Rauan
0 / 0 / 0
: 05.12.2013
: 68
02.02.2014, 16:15     Round Robin #2
C++
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
#include<iostream.h>
#include<stdlib.h>
int main()
{
int st[10], bt[10], wt[10], tat[10], n, tq; /* âðåìÿ âûïîë*å*èÿ, îæèä**èÿ, âûïîë*å*èÿ, êîëè÷åñòâî ïðîöåññîâ, êâ**ò âðåìå*è*/
int i, count=0, swt=0, stat=0, temp, sq=0; /* ïåðåìå**ûå äëÿ âûïîë*å*èÿ ïðîãð*ììû*/
float awt=0.0, atat=0.0; /* îáùåå âðåìÿ îæèä**èÿ è âûïîë*å*èÿ*/
cout<<"Vvedite kolichestvo processov: ";
cin>>n; /* Ââåäèòå êîëè÷åñòâî ïðîöåññîâ*/
for(i=0; i<n;i++) /* Öèêë ð**äîì*î ä*åò ç**÷å*èÿ âðåìå*è âûïî*å*èÿ*/
{
bt[i]=rand()%15;
st[i]=bt[i];
}
cout<<"Vvedite kvant vremeni: "; /* Ââîäèì êâ**ò âðåìå*è*/
cin>>tq; 
while(1) /* Öèêë ñîçä*åò î÷åðåäü â êîòîðîì ê*æäûé ïðîöåññ áóäåò èñïîëüçîâ*òü ÖÏÓ âðåìÿ îïðåäåëå**îå êâ**òîì âðåìå*è*/
{
for(i=0, count=0;i<n;i++) /* Öèêë äëÿ îïðåäåëå*èÿ *îìåð* ïðîöåññ**/
{
temp=tq;  
if(st[i]==0) /* Åñëè âðåìÿ âûïî*å*èÿ ð*â*î *óëþ ïåðåõîäèì ê ñëåä. ïðîöåññó*/
{
count++; 
continue;
}
if(st[i]>tq) /* Åñëè âðåìÿ âûïîë*å*èÿ áîëüøå êâ**ò* âðåìå*è, òî ó÷èòûâ*åì êâ**ò âðåìå*è îò âðåìå*è âûïîë*å*èÿ*/
{
st[i]=st[i]-tq;
}
else
if (st[i]>=0) 
{
temp=st[i];
st[i]=0;
}
sq=sq+temp; /* Âðåìÿ îáîðîò**/
tat[i]=sq; /* Âðåìÿ îæèä**èÿ*/
}
if(n==count) /* Åñëè êîëè÷åñòâî ïðîöåññîâ ç*êî*÷èòüñÿ, òî öèêë ç*êî*÷èòüñÿ*/
break; 
} /* Çäåñü êî*åö öèêë**/
for(i=0;i<n;i++) /* Ýòîò öèêë **õîäèò îáùåå âðåìÿ îæèä**èÿ è âûïîë*å*èÿ*/
{
wt[i]=tat[i]-bt[i];
swt=swt+wt[i];
stat=stat+tat[i];
}
awt=(float)swt/n;
atat=(float)stat/n;
/* Âûâîäèì ïîëó÷å**ûå ä***ûå ** ýêð** êî*ñîëè*/
cout<<endl<<"Process        CPU burst       Wait        Oborot";
/* Íîìåð ïðîöåññ*,Âðåìÿ âûïîë*å*èÿ(ñåðâèñ*),Âðåìÿ îæèä**èÿ,Âðåìÿ îáîðîò**/
cout<<endl;
cout<<endl;
for(i=0; i<n; i++)
{
cout<<i+1<<"\t\t"<<bt[i]<<"\t\t\t"<<wt[i]<<"\t\t"<<tat[i];
cout<<endl;
}
cout<<endl<<"Srednee vremya ojidaniya="<<awt; /*Îáùåå âðåìÿ îæèä**èÿ*/
cout<<endl<<"Srednee polnoe vremya vypolnenia="<<atat;/*Îáùåå âðåìÿ âûïîë*å*èÿ*/
cin.get();
return 0;}
Yandex
02.02.2014, 16:15     Round Robin

: 08:32. GMT +3.
- , ,
-
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
@Mail.ru