Końcowe kody_my_os_lab

#include <iostream>
using namespace std;
struct sjrf
{
    int pid;
    int at;
    int bt;
    int tt;
    int wt;
}processes[10];
int n;

int totalBrust();
int Minimum(int max);
void sort(); // if user not enter processes value in sorted order w.r.t arival time
void Display()
{
    printf("%-15s\t%-15s\t%-15s\t%-15s\t%-15s\n","PID","Arival Time","Brust Time","Terminate Time","Waiting Time");
    for (int i = 0; i < n; ++i) {
        printf("%-15d\t%-15d\t%-15d\t%-15d\t%-15d\n",processes[i].pid,processes[i].at,processes[i].bt,processes[i].tt,processes[i].wt);
    }
}
int final;
int main() {
    cout<<"Enter number of processes : ";
    cin >>n;
    int temp[n];
    for (int i = 0; i < n; ++i) {
        processes[i].pid =i;
        cout<<"Enter Arival and brust tiem of process "<<i<<" : ";
        cin>>processes[i].at>>processes[i].bt;
        temp[i] = processes[i].bt;
    }
    Display();
    int p=0;
    int current =0;
    final = totalBrust();
    for (int j = 0; j <final; ++j) {
        if(processes[p].at ==j)
        {
            p++;
            current = Minimum(p);
        }
        processes[current].bt--;
        if(processes[current].bt == 0)
        {
            processes[current].tt = j+1;
            current = Minimum(p);
        }

    }
    int totalWT=0;
    for (int k = 0; k < n; ++k) {
        processes[k].bt = temp[k];
        processes[k].wt = processes[k].tt - processes[k].bt - processes[k].at;
        totalWT = totalWT + processes[k].wt;
    }

    Display();
    cout<<"Total Waiting Time : "<<(totalWT /(float)n);
}
int Minimum(int max)
{
    int min=0;
    int temp = final;
    for (int i = 0; i < max; ++i) {
        if(processes[i].bt !=0 && processes[i].bt < temp)
        {
            min = i;
            temp = processes[min].bt;
        }
    }
    return min;
}
int totalBrust()
{
    int s=0;
    for (int i = 0; i <n ; ++i) {
        s += processes[i].bt;
    }
    return s;
}


	
	
	

// #include <iostream>
// using namespace std;
// struct Priority
// {
//     int pid;
//     int at;
//     int bt;
//     int pty;
//     int tt;
//     int wt;
// }processes[10];
// int n;

// int totalBrust();
// int Minimum(int max);
// void Display()
// {
//     printf("%-15s\t%-15s\t%-15s\t%-15s\t%-15s\t%-15s\n","PID","Arival Time","Brust Time","Priority","Terminate Time","Waiting Time");
//     for (int i = 0; i < n; ++i) {
//         printf("%-15d\t%-15d\t%-15d\t%-15d\t%-15d\t%-15d\n",processes[i].pid,processes[i].at,processes[i].bt,processes[i].pty,processes[i].tt,processes[i].wt);
//     }
// }
// int final;
// int main() {
//     cout<<"Enter number of processes : ";
//     cin >>n;
//     int temp[n];
//     for (int i = 0; i < n; ++i) {
//         processes[i].pid =i;
//         cout<<"Enter Arival Brust and priority of process "<<i<<" : ";
//         cin>>processes[i].at>>processes[i].bt>>processes[i].pty;
//         temp[i] = processes[i].bt;
//     }
//     Display();
//     int p=0;
//     int current =0;
//     final = totalBrust();
//     for (int j = 0; j <final; ++j) {
//         if(processes[p].at ==j)
//         {
//             p++;
//             current = Minimum(p);
//         }
//         processes[current].bt--;
//         if(processes[current].bt == 0)
//         {
//             processes[current].tt = j+1;
//             current = Minimum(p);
//         }

//     }
//     int totalWT=0;
//     for (int k = 0; k < n; ++k) {
//         processes[k].bt = temp[k];
//         processes[k].wt = processes[k].tt - processes[k].bt - processes[k].at;
//         totalWT = totalWT + processes[k].wt;
//     }

//     Display();
//     cout<<"Total Waiting Time : "<<(totalWT /(float)n);
// }
// int Minimum(int max)
// {
//     int min=0;
//     int temp = final;
//     for (int i = 0; i < max; ++i) {
//         if(processes[i].bt !=0 && processes[i].pty < temp)
//         {
//             min = i;
//             temp = processes[min].pty;
//         }
//     }
//     return min;
// }
// int totalBrust()
// {
//     int s=0;
//     for (int i = 0; i <n ; ++i) {
//         s += processes[i].bt;
//     }
//     return s;
// }
Important Impala