Advertisement
FaisalAhemdBijoy

round

Oct 29th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.79 KB | None | 0 0
  1. /*
  2. 4
  3. 53
  4. 17
  5. 68
  6. 24
  7. 20
  8. */
  9. /*
  10. Round Robin CPU Scheduling
  11. Enter The process Number
  12. 4
  13. Enter The burst time
  14. 53
  15. 17
  16. 68
  17. 24
  18. Enter The quantum time
  19. 20
  20. Process : 0 Burst time :53
  21. Process : 1 Burst time :17
  22. Process : 2 Burst time :68
  23. Process : 3 Burst time :24
  24. calculation start
  25. process : 0 burst time :33
  26. process : 1 burst time :0
  27. process : 2 burst time :48
  28. process : 3 burst time :4
  29. process : 0 burst time :13
  30. process : 2 burst time :28
  31. process : 3 burst time :0
  32. process : 0 burst time :0
  33. process : 2 burst time :8
  34. process : 2 burst time :0
  35. */
  36. #include<bits/stdc++.h>
  37. using namespace std;
  38. int location[100];
  39. vector<pair<int,int > >v;
  40. int main()
  41. {
  42.     cout<<"Round Robin CPU Scheduling "<<endl;
  43.     int num,burst;
  44.     cout<<"Enter The process Number"<<endl;
  45.     cin>>num;
  46.     vector<pair<int,int> >ans;
  47.     cout<<"Enter The burst time "<<endl;
  48.     for(int i=0; i<num; i++)
  49.     {
  50.         cin>>burst;
  51.         v.push_back(make_pair(i,burst));
  52.  
  53.     }
  54.     int quantum,now=0;
  55.     cout<<"Enter The quantum time"<<endl;
  56.     cin>>quantum;
  57.     for (int i=0; i<num; i++)
  58.     {
  59.         cout<<"Process : "<<v[i].first<<" Burst time :"<<v[i].second<<endl;
  60.  
  61.     }
  62.     bool flag=0;
  63.     cout<<"calculation start"<<endl;
  64.     int sum=0;
  65.     while (1)
  66.     {
  67.         flag=0;
  68.  
  69.         for (int i=0,j=now; i<num; j++, i++)
  70.         {
  71.             j%=num;
  72.             flag=0;
  73.             if(v[j].second >0 )
  74.             {
  75.                 flag=1;
  76.                 ans.push_back(make_pair(j,sum));
  77.                 sum=sum+min(quantum,v[j].second);
  78.                 v[j].second= v[j].second- min(quantum,v[j].second);
  79.                 cout<<"process : "<<j<<" burst time :"<<v[j].second<<endl;
  80.  
  81.                 now=j+1;
  82.                 break;
  83.             }
  84.  
  85.  
  86.         }
  87.         if (flag==0)
  88.         {
  89.             break;
  90.         }
  91.     }
  92.     cout<<"Sequence"<<endl;
  93.     for (int i=0; i<ans.size(); i++)
  94.     {
  95.         cout<<"P: "<<ans[i].first<<"->"<<ans[i].second<<endl;
  96.     }
  97.     cout<<endl;
  98.     for (int i=0;i<ans.size();i++)
  99.     {
  100.         for (int j=0;j<num;j++){
  101.             if(ans[i].first == j)
  102.             {
  103.                 location[j]+=1;
  104.             }
  105.         }
  106.     }
  107.     cout<<"location"<<endl;
  108.     for (int i=0;i<num;i++){
  109.         cout<<location[i]<<"  -> ";
  110.     }
  111.     cout<<endl;
  112.  
  113.  
  114. }
  115. /*
  116. Round Robin CPU Scheduling
  117. Enter The process Number
  118. 4
  119. Enter The burst time
  120. 53
  121. 17
  122. 68
  123. 24
  124. Enter The quantum time
  125. 20
  126. Process : 0 Burst time :53
  127. Process : 1 Burst time :17
  128. Process : 2 Burst time :68
  129. Process : 3 Burst time :24
  130. calculation start
  131. process : 0 burst time :33
  132. process : 1 burst time :0
  133. process : 2 burst time :48
  134. process : 3 burst time :4
  135. process : 0 burst time :13
  136. process : 2 burst time :28
  137. process : 3 burst time :0
  138. process : 0 burst time :0
  139. process : 2 burst time :8
  140. process : 2 burst time :0
  141. Sequence
  142. P: 0->20
  143. P: 1->37
  144. P: 2->57
  145. P: 3->77
  146. P: 0->97
  147. P: 2->117
  148. P: 3->121
  149. P: 0->134
  150. P: 2->154
  151. P: 2->162
  152. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement