همین الگریتم به کمک فایل بدون اینتر فیس
کد:
#include <iostream>
struct job
{
char jid[10];
int at;
int bt;
int wt;
int tt;
}jq[10],rq[100];
int front_jq=0,rear_jq=0;
int front_rq=0,rear_rq=0;
int rt[100];
void gantt_chart(int q)
{
FILE *fp;
fp = fopen ("out.txt","a");
int i,k,val,j=rq[0].at;
fprintf (fp, "\n\nGANTT CHART\n");
for(i=0;i<rear_rq;i++)
{
for(k=0;k<rt[i];k++)
printf("__");
fprintf (fp, " ");
}
fprintf (fp, "\n");
for(i=0;i<rear_rq;i++)
{
printf("%s",rq[i].jid);
for(k=0;k<rt[i]-1;k++)
fprintf (fp, " ");
fprintf (fp," ");
}
fprintf (fp, "\n");
for(i=0;i<rear_rq;i++)
{
for(k=0;k<rt[i];k++)
printf("__");
fprintf (fp, " ");
}
fprintf (fp, "\n");
for(i=0;i<rear_rq;i++)
{
if(j<10)
fprintf (fp, ""+j);
else
fprintf (fp, ""+j);
for(k=0;k<rt[i]-1;k++)
fprintf (fp, " ");
fprintf (fp, " ");
j+=rt[i];
}
}
int main()
{
float avg_wt=0,avg_tt=0;
int n=0,i,j,q;
FILE *fp;
fp=fopen("rr.txt","r");
fscanf(fp,"%d\n",&q);
do
{
fscanf(fp,"%s\t%d\t%d\n",jq[n].jid,&jq[n].at,&jq[n].bt);
jq[n].wt=0;
jq[n].tt=0;
n++;
}
while(!feof(fp));
fclose(fp);
rear_jq=n;
// rr_scheduling(q,n);
fp = fopen ("out.txt","a");
for(i=0;i<n;i++)
jq[i].tt=jq[i].bt+jq[i].wt;
fprintf (fp, "\nSCHEDULING\n");
for(i=0;i<rear_rq;i++)
{
if(i==rear_rq-1)
fprintf (fp, rq[i].jid);
else
fprintf (fp, rq[i].jid);
}
gantt_chart(q);
fprintf (fp, "\n\nJID\tAT\tBT\tWT\tTT\n");
for(i=0;i<n;i++)
{
fprintf (fp, "%s\t%d\t%d\t%d\t%d\n",jq[i].jid,jq[i].at,jq[i].bt,jq[i].wt,jq[i].tt+"\n");
avg_wt+=jq[i].wt;
avg_tt+=jq[i].tt;
}
//fprintf (fp, "Average Waiting Time:: \n"+(avg_wt)+"\n");
//fprintf (fp, "Average Turnaround Time:: "+(avg_tt)+"\n");
fclose (fp);
return 0;
}