Advertisement
Kaidul

fcfs

Jan 29th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. /**
  2.  * author : kaidul
  3. **/
  4. using namespace std;
  5. #include <iostream>
  6. #include <cstdio>
  7. #include <vector>
  8. #include <algorithm>
  9.  
  10. #define M 100
  11.  
  12. struct process {
  13.     int arrivalTime, burstTime, priority;
  14.     int waitingTime, turnAroundTime, responseTime;
  15.     bool operator < (const process& a) const {
  16.         if(arrivalTime == a.arrivalTime) return burstTime > a.burstTime;
  17.         return arrivalTime > a.arrivalTime;
  18.     }
  19. } pArray[M];
  20.  
  21.  
  22. int nProcess, timeInterval, total, sum, averageTime;
  23. float  throughtputTime;
  24.  
  25. int main() {
  26.     freopen("in.txt", "r", stdin);
  27.     cin >> nProcess;
  28.  
  29.     for (int i = 0; i < nProcess ; i++) {
  30.         cin >> pArray[i].arrivalTime >> pArray[i].burstTime >> pArray[i].priority;
  31.     }
  32.     cin >> timeInterval;
  33.  
  34.     cout << "First Come, first serve: \n";
  35.     total = 0, sum = 0;
  36.     /**
  37.      In first come, first serve :
  38.       waiting time = response time
  39.       turnaround time = waiting time + burst time
  40.       and
  41.       throughout time = number of process / total time
  42.         where total time = sum of burst time of all processes
  43.     **/
  44.  
  45.     for (int i = 0; i < nProcess; i++) {
  46.         pArray[i].waitingTime = total - pArray[i].arrivalTime;
  47.         cout << (i+1) << "\n";
  48.         cout << "waiting Time : " << pArray[i].waitingTime << "\n";
  49.         pArray[i].responseTime = pArray[i].waitingTime;
  50.         cout << "Response Time : " << pArray[i].responseTime << "\n";
  51.         pArray[i].turnAroundTime = pArray[i].waitingTime + pArray[i].burstTime;
  52.         cout << "turnAround Time : " << pArray[i].turnAroundTime << "\n\n";
  53.         total += pArray[i].burstTime;
  54.         sum += pArray[i].waitingTime;
  55.     }
  56.  
  57.     averageTime = sum / nProcess;
  58.     throughtputTime = (float)nProcess / total;
  59.     cout << "Throughput Time : " << throughtputTime << "\n";
  60.  
  61.  
  62.     cout << "\nAverage Waiting Time : " << averageTime << "\n";
  63.  
  64.     return false;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement