#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#include<iomanip.h>
void main()
{
clrscr();
int i,j,c,rart[20],rsrt[20],art[20],srt[20],srtb[20],srte[20],cuwq[20],cuss[20],idts[20];
float pa[9],ps[7],iart;
int wtime=0;
float wcust=0.0;
float tservice=0.0;
float tidle=0.0;
float time_arr=0.0;
float time_spent=0.0;
cout<<"Enter no of inter arrival times ( less than 8 minutes)";
cin>>iart;
pa[0]=0;ps[0]=0;
for(i=1;i<=iart;i++)
pa[i]=(float)((1/iart)*1000);
for(i=1;i<=6;i++)
{
cout<<"\nEnter probability for service time "<<i<<" minute";
cin>>ps[i];
ps[i]*=100;
}
cout<<"Enter number of customers (number should be less than 20)";
cin>>c;
for(i=1;i<=iart;i++)
pa[i]+=pa[i-1];
for(i=1;i<=6;i++)
ps[i]+=ps[i-1];
for(i=0;i<c;i++)
{
rart[i]=random(1000);
rsrt[i]=random(100);
for(j=0;j<iart;j++)
{
if(rart[i]>pa[j] && rart[i]<=pa[j+1])
art[i]=j+1;
}
for(j=0;j<6;j++)
{
if( rsrt[i]==0)
srt[i]=6;
if(rsrt[i]>ps[j] && rsrt[i]<=ps[j+1])
srt[i]=j+1;
}
}
art[0]=0;
for(i=1;i<=(iart+1);i++)
art[i]+=art[i-1];
srtb[0]=0;
srte[0]=srtb[0]+srt[0];
for(i=1;i<c;i++)
{
if(art[i]>srte[i-1])
srtb[i]=art[i];
else
srtb[i]=srte[i-1];
srte[i]=srtb[i]+srt[i];
}
idts[0]=0;
for(i=0;i<c;i++)
{
cuwq[i]=srtb[i]-art[i];
cuss[i]=cuwq[i]+srt[i];
if(i>0)
idts[i]=srtb[i]-srte[i-1];
}
for(i=0;i<c;i++)
{
wtime=cwq[i]+wtime;
tservice=st[i]+tservice;
tidle=its[i]+tidle;
time_arr=at[i]+time_arr;
time_spent=css[i]+time_spent;
if(cwq[i]!=0)
wcust++;
}
clrscr();
cout<<"\ncust at st tsb tse cwq css its";
for(i=0;i<c;i++)
cout<<"\n"<<setw(5)<<i+1<<setw(7)<<at[i]<<setw(5)<<st[i]<<setw(5)<<stb[i]<<setw(6)<<ste[i]<<setw(6)<<cwq[i]<<setw(6)<<css[i]<<setw(6)<<its[i];
cout<<"\nAVERAGE WAITING TINE FOR CUSTOMERS"<<"\n"<<wtime/c<<"\n";
cout<<"PROBABILITY THAT CUSTOMER HAS TO WAIT IN QUEUE"<<"\n"<<wcust/c<<"\n";
cout<<"FRACTION OF IDLE TIME OF SERVER"<<"\n"<<tidle/tservice<<"\n";
cout<<"AVERAGE SERVICE TIME "<<"\n"<<tservice/c<<"\n";
cout<<"AVERAGE TIME BETWEEN ARRIVAL"<<"\n"<<time_arr/(c-1)<<"\n";
cout<<"AVERAGE WAITING TIME FOR THOSE WHO WAIT"<<"\n"<<wtime/wcust<<"\n";
cout<<"AVERAGE TIME CUSTOMER SPENDS ON SYSTEM"<<"\n"<<time_spent/c<<"\n";
getch();
}
#include<iostream.h>
#include<stdlib.h>
#include<iomanip.h>
void main()
{
clrscr();
int i,j,c,rart[20],rsrt[20],art[20],srt[20],srtb[20],srte[20],cuwq[20],cuss[20],idts[20];
float pa[9],ps[7],iart;
int wtime=0;
float wcust=0.0;
float tservice=0.0;
float tidle=0.0;
float time_arr=0.0;
float time_spent=0.0;
cout<<"Enter no of inter arrival times ( less than 8 minutes)";
cin>>iart;
pa[0]=0;ps[0]=0;
for(i=1;i<=iart;i++)
pa[i]=(float)((1/iart)*1000);
for(i=1;i<=6;i++)
{
cout<<"\nEnter probability for service time "<<i<<" minute";
cin>>ps[i];
ps[i]*=100;
}
cout<<"Enter number of customers (number should be less than 20)";
cin>>c;
for(i=1;i<=iart;i++)
pa[i]+=pa[i-1];
for(i=1;i<=6;i++)
ps[i]+=ps[i-1];
for(i=0;i<c;i++)
{
rart[i]=random(1000);
rsrt[i]=random(100);
for(j=0;j<iart;j++)
{
if(rart[i]>pa[j] && rart[i]<=pa[j+1])
art[i]=j+1;
}
for(j=0;j<6;j++)
{
if( rsrt[i]==0)
srt[i]=6;
if(rsrt[i]>ps[j] && rsrt[i]<=ps[j+1])
srt[i]=j+1;
}
}
art[0]=0;
for(i=1;i<=(iart+1);i++)
art[i]+=art[i-1];
srtb[0]=0;
srte[0]=srtb[0]+srt[0];
for(i=1;i<c;i++)
{
if(art[i]>srte[i-1])
srtb[i]=art[i];
else
srtb[i]=srte[i-1];
srte[i]=srtb[i]+srt[i];
}
idts[0]=0;
for(i=0;i<c;i++)
{
cuwq[i]=srtb[i]-art[i];
cuss[i]=cuwq[i]+srt[i];
if(i>0)
idts[i]=srtb[i]-srte[i-1];
}
for(i=0;i<c;i++)
{
wtime=cwq[i]+wtime;
tservice=st[i]+tservice;
tidle=its[i]+tidle;
time_arr=at[i]+time_arr;
time_spent=css[i]+time_spent;
if(cwq[i]!=0)
wcust++;
}
clrscr();
cout<<"\ncust at st tsb tse cwq css its";
for(i=0;i<c;i++)
cout<<"\n"<<setw(5)<<i+1<<setw(7)<<at[i]<<setw(5)<<st[i]<<setw(5)<<stb[i]<<setw(6)<<ste[i]<<setw(6)<<cwq[i]<<setw(6)<<css[i]<<setw(6)<<its[i];
cout<<"\nAVERAGE WAITING TINE FOR CUSTOMERS"<<"\n"<<wtime/c<<"\n";
cout<<"PROBABILITY THAT CUSTOMER HAS TO WAIT IN QUEUE"<<"\n"<<wcust/c<<"\n";
cout<<"FRACTION OF IDLE TIME OF SERVER"<<"\n"<<tidle/tservice<<"\n";
cout<<"AVERAGE SERVICE TIME "<<"\n"<<tservice/c<<"\n";
cout<<"AVERAGE TIME BETWEEN ARRIVAL"<<"\n"<<time_arr/(c-1)<<"\n";
cout<<"AVERAGE WAITING TIME FOR THOSE WHO WAIT"<<"\n"<<wtime/wcust<<"\n";
cout<<"AVERAGE TIME CUSTOMER SPENDS ON SYSTEM"<<"\n"<<time_spent/c<<"\n";
getch();
}