Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- arr[99].remain_time = 9999;
- //No of process in variable n
- int n;
- cout << "nPlease enter the Number of Processor: ";
- cin >> n;
- cout << endl;
- system("CLS");
- //Take the Burst time for each process by using loop
- for (int i = 0; i < n; i++) {
- cout << endl;
- cout << "Enter the Arrival Time of Process " << i + 1 << " : ";
- cin >> arr[i].arrival_time;
- //increment the process_id by 1 after each burst_time
- arr[i].process_id = i + 1;
- cout << "Enter the Burst Time : ";
- cin >> arr[i].burst_time;
- //copy each process burst_time to another array remain_time[]
- arr[i].remain_time = arr[i].burst_time;
- }
- system("CLS");
- waiting_time(arr, n);
- system("PAUSE");
- return 0;
- cout << "nnProcess Finisht| Turnaround Time | Waiting Time | Response Timenn";
- // handle the INDEX of array process_finish.
- int process_f = 0;
- int* responseTime = new int[n];
- int* counterTime = new int[n];
- for (int i = 0; i < n; i++) {
- responseTime[i] = 0;
- counterTime[n] = 0;
- }
- for (int time = 0; remain != n; time++) {
- smallest = 99;
- for (int i = 0; i < n; i++) {
- if ((a[i].arrival_time <= time) && (a[i].remain_time < a[smallest].remain_time) && (a[i].remain_time > 0)) {
- smallest = i;
- }
- }
- if (counterTime[smallest] == 0) {
- responseTime[smallest] = time;
- counterTime[smallest] = 1;
- }
- a[smallest].remain_time--;
- if (a[smallest].remain_time == 0) {
- //to assign a process # which finish the total job
- process_finish[process_f] = smallest + 1;
- process_f++;
- //to assign a process_id
- a[smallest].process_id = smallest + 1;
- int tt, rt, wt;
- //One process complete the total job
- remain++;
- //Total completion time of process
- endTime = time + 1;
- //Calculate the TURNaround TIME (completionTime - TT )
- tt = endTime - a[smallest].arrival_time;
- //Calculate the Waiting Time
- wt = a[smallest].waiting_time = tt - a[smallest].burst_time;
- //Calculate the Response Time (completionTime - TT ) +++++++++++++
- rt = responseTime[smallest] - a[smallest].arrival_time;
- if (rt < 0)
- rt += abs(rt);
- cout << "ntP[" << smallest + 1 << "]t|t" << tt << "t|t" << wt << "t|t" << rt;
- //For Average Waiting Time
- sum_wait += wt;
- //For Average Turnaround Time
- sum_turn += tt;
- //For Average Response Time
- sum_resp += rt;
- }
- }
- cout << "nnAverage waiting time =" << sum_wait * 1.0 / n;
- cout << "nnAverage turnaround time =" << sum_turn * 1.0 / n;
- cout << "nnAverage response time =" << sum_resp * 1.0 / n;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement