New paste Repaste Download
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
    int n = 5;
    int bt[5] = {10, 1, 2, 1, 5};
    int pr[5] = {3, 1, 3, 4, 2};
    int pid[5] = {1, 2, 3, 4, 5};
    int ct[5], tat[5], wt[5];
    bool visited[5] = {false};
    int time = 0;
    for (int i = 0; i < n; i++) {
        int highest = -1;
        for (int j = 0; j < n; j++) {
            if (!visited[j]) {
                if (highest == -1 || pr[j] < pr[highest]) {
                    highest = j;
                }
            }
        }
        time += bt[highest];
        ct[highest] = time;
        tat[highest] = ct[highest]; // AT=0
        wt[highest] = tat[highest] - bt[highest];
        visited[highest] = true;
    }
    cout << left << setw(10) << "Process"
         << setw(10) << "BT"
         << setw(10) << "Priority"
         << setw(15) << "CT"
         << setw(15) << "TAT"
         << setw(15) << "WT" << endl;
    float total_wt = 0;
    for (int i = 0; i < n; i++) {
        cout << left << setw(10) << ("P" + to_string(pid[i]))
             << setw(10) << bt[i]
             << setw(10) << pr[i]
             << setw(15) << ct[i]
             << setw(15) << tat[i]
             << setw(15) << wt[i] << endl;
        total_wt += wt[i];
    }
    cout << "\nAverage Waiting Time = " << (total_wt / n) << " ms" << endl;
    return 0;
}
Filename: None. Size: 1kb. View raw, , hex, or download this file.

This paste expires on 2025-08-24 09:26:02.968692. Pasted through web.