Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. arr[99].remain_time = 9999;
  2.  
  3. //No of process in variable n
  4. int n;
  5.  
  6. cout << "nPlease enter the Number of Processor: ";
  7.  
  8. cin >> n;
  9.  
  10. cout << endl;
  11.  
  12. system("CLS");
  13.  
  14. //Take the Burst time for each process by using loop
  15. for (int i = 0; i < n; i++) {
  16. cout << endl;
  17. cout << "Enter the Arrival Time of Process " << i + 1 << " : ";
  18.  
  19. cin >> arr[i].arrival_time;
  20.  
  21. //increment the process_id by 1 after each burst_time
  22. arr[i].process_id = i + 1;
  23.  
  24. cout << "Enter the Burst Time : ";
  25.  
  26. cin >> arr[i].burst_time;
  27.  
  28. //copy each process burst_time to another array remain_time[]
  29. arr[i].remain_time = arr[i].burst_time;
  30. }
  31.  
  32. system("CLS");
  33. waiting_time(arr, n);
  34.  
  35. system("PAUSE");
  36. return 0;
  37.  
  38. cout << "nnProcess Finisht| Turnaround Time | Waiting Time | Response Timenn";
  39.  
  40. // handle the INDEX of array process_finish.
  41. int process_f = 0;
  42. int* responseTime = new int[n];
  43. int* counterTime = new int[n];
  44.  
  45. for (int i = 0; i < n; i++) {
  46. responseTime[i] = 0;
  47. counterTime[n] = 0;
  48. }
  49.  
  50. for (int time = 0; remain != n; time++) {
  51. smallest = 99;
  52.  
  53. for (int i = 0; i < n; i++) {
  54. if ((a[i].arrival_time <= time) && (a[i].remain_time < a[smallest].remain_time) && (a[i].remain_time > 0)) {
  55. smallest = i;
  56. }
  57.  
  58. }
  59.  
  60. if (counterTime[smallest] == 0) {
  61. responseTime[smallest] = time;
  62. counterTime[smallest] = 1;
  63. }
  64. a[smallest].remain_time--;
  65.  
  66. if (a[smallest].remain_time == 0) {
  67. //to assign a process # which finish the total job
  68. process_finish[process_f] = smallest + 1;
  69.  
  70. process_f++;
  71.  
  72. //to assign a process_id
  73. a[smallest].process_id = smallest + 1;
  74.  
  75. int tt, rt, wt;
  76.  
  77. //One process complete the total job
  78. remain++;
  79.  
  80. //Total completion time of process
  81. endTime = time + 1;
  82.  
  83. //Calculate the TURNaround TIME (completionTime - TT )
  84. tt = endTime - a[smallest].arrival_time;
  85.  
  86. //Calculate the Waiting Time
  87. wt = a[smallest].waiting_time = tt - a[smallest].burst_time;
  88.  
  89. //Calculate the Response Time (completionTime - TT ) +++++++++++++
  90. rt = responseTime[smallest] - a[smallest].arrival_time;
  91. if (rt < 0)
  92. rt += abs(rt);
  93.  
  94.  
  95. cout << "ntP[" << smallest + 1 << "]t|t" << tt << "t|t" << wt << "t|t" << rt;
  96.  
  97. //For Average Waiting Time
  98. sum_wait += wt;
  99.  
  100. //For Average Turnaround Time
  101. sum_turn += tt;
  102.  
  103. //For Average Response Time
  104. sum_resp += rt;
  105. }
  106.  
  107. }
  108.  
  109. cout << "nnAverage waiting time =" << sum_wait * 1.0 / n;
  110. cout << "nnAverage turnaround time =" << sum_turn * 1.0 / n;
  111. cout << "nnAverage response time =" << sum_resp * 1.0 / n;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement