|
| 1 | +#include<iostream> |
| 2 | +using namespace std; |
| 3 | + |
| 4 | +int processes[20], at[20], bt[20], ct[20],wt[20], tat[20],rt[20]; |
| 5 | + |
| 6 | +void completionTime( int n) |
| 7 | +{ |
| 8 | + ct[0] = bt[0]; |
| 9 | + cout<< "\nCompletion Time: "<< ct[0] << "\t"; |
| 10 | + for(int i = 1; i<n; i++) |
| 11 | + { |
| 12 | + ct[i] = ct[i-1] + bt[i]; |
| 13 | + cout<< ct[i] << "\t"; |
| 14 | + } |
| 15 | + |
| 16 | +} |
| 17 | + |
| 18 | +void turnAroundTime(int n) |
| 19 | +{ |
| 20 | + tat[n] = {0}; |
| 21 | + cout<< "\nTurn Around Time:"; |
| 22 | + for (int i = 0; i < n ; i++) |
| 23 | + { |
| 24 | + tat[i] = ct[i] - at[i]; |
| 25 | + cout<< tat[i] << "\t" ; |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +void waitingTime(int n) |
| 30 | +{ |
| 31 | + wt[n] = {0}; |
| 32 | + wt[0] = 0; |
| 33 | + cout<< "\nWaiting Time: "<< wt[0] << "\t"; |
| 34 | + for (int i = 1; i < n ; i++ ) |
| 35 | + { |
| 36 | + wt[i] = tat[i] - bt[i]; |
| 37 | + cout<< wt[i] << "\t"; |
| 38 | + } |
| 39 | +} |
| 40 | +void responseTime(int n) |
| 41 | +{ |
| 42 | + rt[0]=at[0]; |
| 43 | + cout<< "\nResponse Time: "<< wt[0] << "\t"; |
| 44 | + for (int i = 1; i < n ; i++ ) |
| 45 | + { |
| 46 | + rt[i] = ct[i-1]; |
| 47 | + cout<< rt[i] << "\t"; |
| 48 | + } |
| 49 | +} |
| 50 | +void findAvgTime( int n) |
| 51 | +{ |
| 52 | + int total_wt = 0, total_tat = 0,total_rt = 0; |
| 53 | + completionTime(n); |
| 54 | + turnAroundTime(n); |
| 55 | + waitingTime(n); |
| 56 | + responseTime(n); |
| 57 | + |
| 58 | + for (int i=0; i<n; i++) |
| 59 | + { |
| 60 | + total_wt = total_wt + wt[i]; |
| 61 | + total_tat = total_tat + tat[i]; |
| 62 | + total_rt += rt[i]; |
| 63 | + } |
| 64 | + |
| 65 | + cout << "\n"; |
| 66 | + cout << "\nAverage Turn Around Time = " << (float)total_tat / (float)n; |
| 67 | + cout << "\nAverage Waiting Time = " << (float)total_wt / (float)n; |
| 68 | + cout << "\nAverage Response time = " << (float)total_rt / (float)n; |
| 69 | + cout << "\n"; |
| 70 | +} |
| 71 | + |
| 72 | +int main() |
| 73 | +{ |
| 74 | + int pro, i; |
| 75 | + cout << "Enter the number of processes: "; |
| 76 | + cin >> pro; |
| 77 | + cout << "Enter the process number, arrival time and burst time for the above processes:\n"; |
| 78 | + for(i=0; i<pro; i++) |
| 79 | + { |
| 80 | + cin >> processes[i] >> at[i] >> bt[i]; |
| 81 | + } |
| 82 | + cout << "Process ID: "; |
| 83 | + for(i=0; i<pro; i++) |
| 84 | + { |
| 85 | + cout << processes[i] << "\t"; |
| 86 | + } |
| 87 | + cout << "\nArrival time: "; |
| 88 | + for(i=0; i<pro; i++) |
| 89 | + { |
| 90 | + cout << at[i] << "\t"; |
| 91 | + } |
| 92 | + cout << "\nBurst time: "; |
| 93 | + for(i=0; i<pro; i++) |
| 94 | + { |
| 95 | + cout << bt[i] << "\t"; |
| 96 | + } |
| 97 | + |
| 98 | + findAvgTime(pro); |
| 99 | + return 0; |
| 100 | +} |
| 101 | + |
0 commit comments