Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- bool cmp(pair<int,pair<int,int> > a, pair<int,pair<int,int> >b)
- {
- return a.second.second>b.second.second;
- }
- int main()
- {
- int no_of_proc;
- cout<<"Enter number of process: ";
- cin>>no_of_proc;
- vector< pair<int,pair<int,int> > > proc;
- cout<<"Enter process ID and burst time of process as follows: "<<endl;
- for(int i=0; i<no_of_proc; i++)
- {
- int bur,prio,id;
- cout<<"Process ID : " ;
- cin>>id;
- cout<<"Burst Time : " ;
- cin>>bur;
- cout<<"Priority : " ;
- cin>>prio;
- cout<<endl;
- proc.push_back({id,{bur,prio}});
- }
- sort(proc.begin(),proc.end(),cmp);
- // for(int i=0; i<proc.size(); i++)cout<<proc[i].first<<" "<<proc[i].second.first<<" "<<proc[i].second.second<<endl;
- int tat[100];
- tat[0]=proc[0].second.first;
- double sum1=(double)tat[0];
- for(int i=1; i<proc.size(); i++)
- {
- tat[i]=(tat[i-1]+proc[i].second.first);
- sum1+=(double)tat[i];
- }
- int wait[100];
- double sum2=0;
- for(int i=0; i<proc.size(); i++)
- {
- wait[i]=tat[i]-proc[i].second.first;
- sum2+=(double)wait[i];
- }
- cout<<"Gantt Chart:: " <<endl;
- cout<<"Process ID"<<" "<<"Turn around Time "<<"Waiting Time"<<endl;
- for(int i=0; i<proc.size(); i++)
- {
- cout<<proc[i].first<<" "<<tat[i]<<" "<<wait[i]<<endl;
- }
- double avgwait=sum2/no_of_proc;
- double avgtat=sum1/no_of_proc;
- cout<<"Average waiting time: "<<avgwait<<endl;
- cout<<"Average turn around time: "<<avgtat<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement