0
#include <iostream>
#include <conio>
# include <string>

int main()
{
    double avgwt,avgtt;
    char pname[10][10], c[10][10];
    int wt[10],tt[10],bt[10],pt[10],t,q,i,n, s;
   int sum=0,sbt=0,j,ss=10,arr[10];

    cout <<"\n\n\t\t\t----Priority Scheduling----";
    cout <<"\n\n\tEnter the number of processes : ";
    cin >>n;

    for(i=0;i<n;i++)
    {
        cout <<"\n\n\n\ntEnter The Process Name : ";
        cin >>pname[i];
        cout <<"\n\tEnter The Arrival Time : ";
        cin >>arr[i];
        cout <<"\n\tEnter The CPU Time :";
        cin >>bt[i];
      cout <<"\n\tPriority of process: ";
        cin >>pt[i];
    }

    for(i=0;i<n;i++)
        for(j=i+1;j<n;j++)
        {
            if(pt[i]>pt[j])
            {
                t=pt[i];
                pt[i]=pt[j];
                pt[j]=t;
                q=bt[i];
                bt[i]=bt[j];
                bt[j]=q;
                s=arr[i];
                arr[i]=arr[j];
                arr[j]=s;
                strcpy(c[i],pname[i]);
                strcpy(pname[i],pname[j]);
                strcpy(pname[j],c[i]);
            }
        }

        wt[0]=0;
        for(i=0;i<n;i++)
        {
            wt[i+1]=wt[i]+bt[i];
            sum=sum+wt[i];
            sbt=sbt+wt[i+1];
            tt[i]=wt[i]+bt[i];
            ss=ss+bt[i];
      }

        cout <<"\n\n\tPosition Process Based On Priority";
        cout <<"\n----------------------------------------------------------------------\n";

    for(i=0;i<n;i++)
        {
            cout <<"|\t\t"<<pt[i];
      }

    cout <<"\n----------------------------------------------------------------------\n";
    for(i=0;i<n;i++)
    {
        cout <<"\t\t"<<wt[i];
   }

    cout <<"\n"<<ss;
    cout <<"\n----------------------------------------------------------------------\n";
    cout <<"\n\n\tWAITING TIME of the process = "<<sum;
    cout <<"\n\n\tTotal TURNAROUND TIME of the process = "<<t;

    avgwt=(float)sum/n;
    avgtt=(float)sbt/n;

    cout <<"\n\n\tAverage WAITING TIME of the process = "<<avgwt;
    cout <<"\n\n\tAverage TURNAROUND TIME of the process = "<<avgtt;
    getch();
}

--DON'T KNOW HOW TO CALCULATE AVERAGE WAITING TIME AND TURNAROUND TIME IF CODING NEED USER TO ENTER ARRIVAL TIME... I JUST KNOW IF THE CODING GENERATE INDEPENDENTLY THE ARRIVAL TIME... CAN SOMEONE HELP ME....

Edited by Reverend Jim: Fixed formatting

1
Contributor
1
Reply
3
Views
6 Years
Discussion Span
Last Post by saliza
0

i will grateful if someone can help me in a short time because i need it around this week... thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.