#include
#include
#include
typedef struct
{
int cno,in_arr,arr,ser_time,tsb,tse,wait,tsis,idle;
}customer;
int lookup1(int c)
{
if(c>=0 && c<13 font="font">13>
{
return 1;
}
else if(c>=13 && c<25 font="font">25>
{
return 2;
}
else if(c>=25 && c<38 font="font">38>
{
return 3;
}
else if(c>=38 && c<50 font="font">50>
{
return 4;
}
else if(c>=50 && c<63 font="font">63>
{
return 5;
}
else if(c>=63 && c<75 font="font">75>
{
return 6;
}
else if(c>=75 && c<87 font="font">87>
{
return 7;
}
return 8;
}
int lookup2(int c)
{
if(c>=0 && c<11 font="font">11>
{
return 1;
}
else if(c>=11 && c<31 font="font">31>
{
return 2;
}
else if(c>=31 && c<61 font="font">61>
{
return 3;
}
else if(c>=61 && c<86 font="font">86>
{
return 4;
}
else if(c>=86 && c<96 font="font">96>
{
return 5;
}
return 6;
}
void prtcust(customer c)
{
printf("\n");
printf("%d\t",c.cno);
printf("%d\t",c.in_arr);
printf("%d\t",c.arr);
printf("%d\t",c.ser_time);
printf("%d\t",c.tsb);
printf("%d\t",c.tse);
printf("%d\t",c.tsis);
printf("%d\t",c.wait);
printf("%d\t",c.idle);
}
customer initialize(customer c)
{
c.cno=1;
c.in_arr=0;
c.arr=0;
c.ser_time=lookup2(rand()%100);
c.tsb=0;
c.tse=c.ser_time;
c.wait=0;
c.idle=0;
c.tsis=c.ser_time;
prtcust(c);
return c;
}
typedef struct
{
char ename;
int time;
}event;
int max(int a,int b)
{
return a>=b?a:b;
}
void prtfel(event fel[],int t,int in,int dp)
{
event temp[3],temp2;
int i,j;
for(i=0;i<3 font="font" i="i">3>
{
temp[i]=fel[i];
}
for(i=0;i<3 font="font" i="i">3>
{
for(j=0;j<3 font="font" j="j">3>
{
if(temp[i].time
{
temp2=temp[i];
temp[i]=temp[j];
temp[j]=temp2;
}
}
}
if(t==temp[0].time)
{
for(i=0;i<3 font="font" i="i">3>
{
printf("(%c,%d) ",temp[i].ename,temp[i].time);
}
printf("\n%d\t",t);
t=temp[0].time;
}
}
int main()
{
customer c[30];
int i,j,k,a,d,e,p,arr=0,dep=0,idle=0,t=0,in=1,dp=0;
event fel[3];
system("cls");
printf("\t\t\tGrocery Shop Simulation\n");
printf("Cstno\tInArr\tArrvl\tSerTm\tTSB\tTSE\tTSpSys\tWait\tIdle");
c[0]=initialize(c[0]);
for(i=1;i<30 font="font" i="i">30>
{
c[i].cno=i+1;
c[i].in_arr=lookup1(rand()%100);
c[i].arr=c[i-1].arr+c[i].in_arr;
c[i].ser_time=lookup2(rand()%100);
c[i].tsb=max(c[i-1].tse,c[i].arr);
c[i].tse=c[i].tsb+c[i].ser_time;
c[i].wait=max(0,c[i].tsb-c[i].arr);
c[i].tsis=c[i].ser_time+c[i].wait;
c[i].idle=max(0,c[i].arr-c[i-1].tse);
prtcust(c[i]);
}
printf("\n\nPress any key to see FEL");
getch();
fel[2].ename='E';
fel[2].time=60;
fel[0].ename='A';
fel[0].time=0;
fel[1].ename='D';
fel[1].time=c[0].ser_time;
system("cls");
printf("\t\t\t FEL\n");
printf("Time \tFEL\n");
printf("%d\t",t);
while(t<60 font="font">60>
{
if(fel[0].time==t)
{
fel[0].time=t+c[in].in_arr;
in++;
}
if(fel[1].time==t)
{
fel[1].time= t+ c[dp].ser_time;
dp++;
}
t++;
prtfel(fel,t,in,dp);
}
getch();
}
#include
#include
typedef struct
{
int cno,in_arr,arr,ser_time,tsb,tse,wait,tsis,idle;
}customer;
int lookup1(int c)
{
if(c>=0 && c<13 font="font">13>
{
return 1;
}
else if(c>=13 && c<25 font="font">25>
{
return 2;
}
else if(c>=25 && c<38 font="font">38>
{
return 3;
}
else if(c>=38 && c<50 font="font">50>
{
return 4;
}
else if(c>=50 && c<63 font="font">63>
{
return 5;
}
else if(c>=63 && c<75 font="font">75>
{
return 6;
}
else if(c>=75 && c<87 font="font">87>
{
return 7;
}
return 8;
}
int lookup2(int c)
{
if(c>=0 && c<11 font="font">11>
{
return 1;
}
else if(c>=11 && c<31 font="font">31>
{
return 2;
}
else if(c>=31 && c<61 font="font">61>
{
return 3;
}
else if(c>=61 && c<86 font="font">86>
{
return 4;
}
else if(c>=86 && c<96 font="font">96>
{
return 5;
}
return 6;
}
void prtcust(customer c)
{
printf("\n");
printf("%d\t",c.cno);
printf("%d\t",c.in_arr);
printf("%d\t",c.arr);
printf("%d\t",c.ser_time);
printf("%d\t",c.tsb);
printf("%d\t",c.tse);
printf("%d\t",c.tsis);
printf("%d\t",c.wait);
printf("%d\t",c.idle);
}
customer initialize(customer c)
{
c.cno=1;
c.in_arr=0;
c.arr=0;
c.ser_time=lookup2(rand()%100);
c.tsb=0;
c.tse=c.ser_time;
c.wait=0;
c.idle=0;
c.tsis=c.ser_time;
prtcust(c);
return c;
}
typedef struct
{
char ename;
int time;
}event;
int max(int a,int b)
{
return a>=b?a:b;
}
void prtfel(event fel[],int t,int in,int dp)
{
event temp[3],temp2;
int i,j;
for(i=0;i<3 font="font" i="i">3>
{
temp[i]=fel[i];
}
for(i=0;i<3 font="font" i="i">3>
{
for(j=0;j<3 font="font" j="j">3>
{
if(temp[i].time
{
temp2=temp[i];
temp[i]=temp[j];
temp[j]=temp2;
}
}
}
if(t==temp[0].time)
{
for(i=0;i<3 font="font" i="i">3>
{
printf("(%c,%d) ",temp[i].ename,temp[i].time);
}
printf("\n%d\t",t);
t=temp[0].time;
}
}
int main()
{
customer c[30];
int i,j,k,a,d,e,p,arr=0,dep=0,idle=0,t=0,in=1,dp=0;
event fel[3];
system("cls");
printf("\t\t\tGrocery Shop Simulation\n");
printf("Cstno\tInArr\tArrvl\tSerTm\tTSB\tTSE\tTSpSys\tWait\tIdle");
c[0]=initialize(c[0]);
for(i=1;i<30 font="font" i="i">30>
{
c[i].cno=i+1;
c[i].in_arr=lookup1(rand()%100);
c[i].arr=c[i-1].arr+c[i].in_arr;
c[i].ser_time=lookup2(rand()%100);
c[i].tsb=max(c[i-1].tse,c[i].arr);
c[i].tse=c[i].tsb+c[i].ser_time;
c[i].wait=max(0,c[i].tsb-c[i].arr);
c[i].tsis=c[i].ser_time+c[i].wait;
c[i].idle=max(0,c[i].arr-c[i-1].tse);
prtcust(c[i]);
}
printf("\n\nPress any key to see FEL");
getch();
fel[2].ename='E';
fel[2].time=60;
fel[0].ename='A';
fel[0].time=0;
fel[1].ename='D';
fel[1].time=c[0].ser_time;
system("cls");
printf("\t\t\t FEL\n");
printf("Time \tFEL\n");
printf("%d\t",t);
while(t<60 font="font">60>
{
if(fel[0].time==t)
{
fel[0].time=t+c[in].in_arr;
in++;
}
if(fel[1].time==t)
{
fel[1].time= t+ c[dp].ser_time;
dp++;
}
t++;
prtfel(fel,t,in,dp);
}
getch();
}
Comments