Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * author : kaidul
- **/
- using namespace std;
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <algorithm>
- #define M 100
- struct process {
- int arrivalTime, burstTime, priority;
- int waitingTime, turnAroundTime, responseTime;
- bool operator < (const process& a) const {
- if(arrivalTime == a.arrivalTime) return burstTime > a.burstTime;
- return arrivalTime > a.arrivalTime;
- }
- } pArray[M];
- int nProcess, timeInterval, total, sum, averageTime;
- float throughtputTime;
- int main() {
- freopen("in.txt", "r", stdin);
- cin >> nProcess;
- for (int i = 0; i < nProcess ; i++) {
- cin >> pArray[i].arrivalTime >> pArray[i].burstTime >> pArray[i].priority;
- }
- cin >> timeInterval;
- cout << "First Come, first serve: \n";
- total = 0, sum = 0;
- /**
- In first come, first serve :
- waiting time = response time
- turnaround time = waiting time + burst time
- and
- throughout time = number of process / total time
- where total time = sum of burst time of all processes
- **/
- for (int i = 0; i < nProcess; i++) {
- pArray[i].waitingTime = total - pArray[i].arrivalTime;
- cout << (i+1) << "\n";
- cout << "waiting Time : " << pArray[i].waitingTime << "\n";
- pArray[i].responseTime = pArray[i].waitingTime;
- cout << "Response Time : " << pArray[i].responseTime << "\n";
- pArray[i].turnAroundTime = pArray[i].waitingTime + pArray[i].burstTime;
- cout << "turnAround Time : " << pArray[i].turnAroundTime << "\n\n";
- total += pArray[i].burstTime;
- sum += pArray[i].waitingTime;
- }
- averageTime = sum / nProcess;
- throughtputTime = (float)nProcess / total;
- cout << "Throughput Time : " << throughtputTime << "\n";
- cout << "\nAverage Waiting Time : " << averageTime << "\n";
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement