dinesh sainani
Mca/4538/10
#include
#include
#include
typedef struct
{
int cn,iarr,arr,stime,b,e,w,tsis,c_idle;
}customer;
int lookup1(int c)
{
if(c>=0 && c<13 p="p"> {
return 1;
}
else if(c>=13 && c<25 p="p"> {
return 2;
}
else if(c>=25 && c<38 p="p"> {
return 3;
}
else if(c>=38 && c<50 p="p"> {
return 4;
}
else if(c>=50 && c<63 p="p"> {
return 5;
}
else if(c>=63 && c<75 p="p"> {
return 6;
}
else if(c>=75 && c<87 p="p"> {
return 7;
}
return 8;
}
int lookup2(int c)
{
if(c>=0 && c<11 p="p"> {
return 1;
}
else if(c>=11 && c<31 p="p"> {
return 2;
}
else if(c>=31 && c<61 p="p"> {
return 3;
}
else if(c>=61 && c<86 p="p"> {
return 4;
}
else if(c>=86 && c<96 p="p"> {
return 5;
}
return 6;
}
void prtcust(customer c)
{
printf("\n");
printf("%d\t",c.cn);
printf("%d\t",c.iarr);
printf("%d\t",c.arr);
printf("%d\t",c.stime);
printf("%d\t",c.b);
printf("%d\t",c.e);
printf("%d\t",c.tsis);
printf("%d\t",c.w);
printf("%d\t",c.c_idle);
}
customer initialize(customer c)
{
c.cn=1;
c.iarr=0;
c.arr=0;
c.stime=lookup2(rand()%100);
c.b=0;
c.e=c.stime;
c.w=0;
c.c_idle=0;
c.tsis=c.stime;
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 br="br" i="i">3>
{
temp[i]=fel[i];
}
for(i=0;i<3 br="br" i="i">3>
{
for(j=0;j<3 br="br" 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 i="i" p="p">
{
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,c_idle=0,t=0,in=1,dp=0;
event fel[3];
system("cls");
printf("\t\t\tGrocery Shop Simulation\n");
printf("Cstno\tInArr\tArrvl\erTm\tb\te\tTSpSys\tw\tc_idle");
c[0]=initialize(c[0]);
for(i=1;i<30 br="br" i="i">30>
{
c[i].cn=i+1;
c[i].iarr=lookup1(rand()%100);
c[i].arr=c[i-1].arr+c[i].iarr;
c[i].stime=lookup2(rand()%100);
c[i].b=max(c[i-1].e,c[i].arr);
c[i].e=c[i].b+c[i].stime;
c[i].w=max(0,c[i].b-c[i].arr);
c[i].tsis=c[i].stime+c[i].w;
c[i].c_idle=max(0,c[i].arr-c[i-1].e);
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].stime;
system("cls");
printf("\t\t\t FEL\n");
printf("Time \tFEL\n");
printf("%d\t",t);
while(t<60 br="br">60>
{
if(fel[0].time==t)
{
fel[0].time=t+c[in].iarr;
in++;
}
if(fel[1].time==t)
{
fel[1].time= t+ c[dp].stime;
dp++;
}
t++;
prtfel(fel,t,in,dp);
}
getch();
}
3> 96>86>61>31>11>87>75>63>50>38>25>13>
Mca/4538/10
#include
#include
#include
typedef struct
{
int cn,iarr,arr,stime,b,e,w,tsis,c_idle;
}customer;
int lookup1(int c)
{
if(c>=0 && c<13 p="p"> {
return 1;
}
else if(c>=13 && c<25 p="p"> {
return 2;
}
else if(c>=25 && c<38 p="p"> {
return 3;
}
else if(c>=38 && c<50 p="p"> {
return 4;
}
else if(c>=50 && c<63 p="p"> {
return 5;
}
else if(c>=63 && c<75 p="p"> {
return 6;
}
else if(c>=75 && c<87 p="p"> {
return 7;
}
return 8;
}
int lookup2(int c)
{
if(c>=0 && c<11 p="p"> {
return 1;
}
else if(c>=11 && c<31 p="p"> {
return 2;
}
else if(c>=31 && c<61 p="p"> {
return 3;
}
else if(c>=61 && c<86 p="p"> {
return 4;
}
else if(c>=86 && c<96 p="p"> {
return 5;
}
return 6;
}
void prtcust(customer c)
{
printf("\n");
printf("%d\t",c.cn);
printf("%d\t",c.iarr);
printf("%d\t",c.arr);
printf("%d\t",c.stime);
printf("%d\t",c.b);
printf("%d\t",c.e);
printf("%d\t",c.tsis);
printf("%d\t",c.w);
printf("%d\t",c.c_idle);
}
customer initialize(customer c)
{
c.cn=1;
c.iarr=0;
c.arr=0;
c.stime=lookup2(rand()%100);
c.b=0;
c.e=c.stime;
c.w=0;
c.c_idle=0;
c.tsis=c.stime;
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 br="br" i="i">3>
{
temp[i]=fel[i];
}
for(i=0;i<3 br="br" i="i">3>
{
for(j=0;j<3 br="br" 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 i="i" p="p">
{
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,c_idle=0,t=0,in=1,dp=0;
event fel[3];
system("cls");
printf("\t\t\tGrocery Shop Simulation\n");
printf("Cstno\tInArr\tArrvl\erTm\tb\te\tTSpSys\tw\tc_idle");
c[0]=initialize(c[0]);
for(i=1;i<30 br="br" i="i">30>
{
c[i].cn=i+1;
c[i].iarr=lookup1(rand()%100);
c[i].arr=c[i-1].arr+c[i].iarr;
c[i].stime=lookup2(rand()%100);
c[i].b=max(c[i-1].e,c[i].arr);
c[i].e=c[i].b+c[i].stime;
c[i].w=max(0,c[i].b-c[i].arr);
c[i].tsis=c[i].stime+c[i].w;
c[i].c_idle=max(0,c[i].arr-c[i-1].e);
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].stime;
system("cls");
printf("\t\t\t FEL\n");
printf("Time \tFEL\n");
printf("%d\t",t);
while(t<60 br="br">60>
{
if(fel[0].time==t)
{
fel[0].time=t+c[in].iarr;
in++;
}
if(fel[1].time==t)
{
fel[1].time= t+ c[dp].stime;
dp++;
}
t++;
prtfel(fel,t,in,dp);
}
getch();
}
Comments