Round Robin

Published on February 2017 | Categories: Documents | Downloads: 27 | Comments: 0 | Views: 224
of 3
Download PDF   Embed   Report

Comments

Content

//round robin #include<stdio.h> #include<conio.h> #include<iostream.h> struct process { int pid; int atime; int wtime; int left; int btime; int ttime; int finish; }pro[5]; int i=0; int finish() { int j; for(j=0;j<i;j++) { if(pro[j].finish==0) { return 0; } } return 1; } void main() { clrscr(); char chart[100]; char symbol[5]={'1','2','3','4','5'}; int choice=1; float awtime=0,attime=0; do { cout<<"Do you have a process?(1/0)\n"; cin>>choice; if(choice==1) { cout<<"Process id:"; cin>>pro[i].pid; cout<<"Arrival time:"; cin>>pro[i].atime; cout<<"Burst time:"; cin>>pro[i].btime; pro[i].left=pro[i].btime; pro[i].finish=0; i++; } }while(choice==1);

clrscr(); cout<<"Gauntt Chart\n"; int tslice=4; int s=0; int flag; int totaltime=0; int j,c; do { flag=1; for(j=0;j<i;j++) { if((pro[j].atime<=totaltime)&&(pro[j].finish==0)) { flag=0; if(pro[j].left>tslice) { pro[j].left=pro[j].left-tslice; totaltime+=tslice; for(int d=0;d<tslice;d++) { textcolor(j+1); cprintf("%c",char(219)); chart[s]=symbol[j]; s++; } }//end of if 2 else { totaltime+=pro[j].left; pro[j].finish=1; pro[j].wtime=totaltime-pro[j].atime-pro[j].btime; pro[j].ttime=totaltime-pro[j].atime; for(int d=0;d<pro[j].left;d++) { textcolor(j+1); cprintf("%c",char(219)); chart[s++]=symbol[j]; } pro[j].left=0; } }//end of for if(flag==1) { c=finish(); if(c!=1) { textcolor(i); cprintf("%c",char(219)); totaltime++; chart[s++]='i'; } }

} }while(c!=1); chart[s]='\0'; cout<<endl; for(int k=0;k<s;k++) { cout<<chart[k]; } cout<<"\n"; cout<<"PID Wtime TTime\n"; for( j=0;j<i;j++) { textcolor(j+1); cprintf("%d %d %d",pro[j].pid,pro[j].wtime,pro[j].ttime); cout<<endl; } for(j=0;j<i;j++) { awtime+=pro[j].wtime; attime+=pro[j].ttime; } printf("Average waiting time:%fms\n",awtime/i); printf("Average turnaround time:%fms",attime/i); getch();

}

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close