How to find waiting time in a single server queue system?

Source Code:

//single server queuing system
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int n, i, a[10], s[10], w[10];
float wa=0.0;
cout<<"\n***SINGLE SERVER QUEUING SYSTEM***"<<endl;
cout<<"Get Ready!!! You are in!!!"<<endl;
cout<<"\nPress any key to run..."<<endl;
getch();
cout<<endl;
cout<<"Enter the number of customers: ";
cin>>n;
cout<<"Enter the arrival times of "<<n<<" customers: ";
for(i=1; i<=n; i++)
cin>>a[i];
cout<<"Enter the service times of "<<n<<" customers: ";
for(i=1; i<=n; i++)
cin>>s[i];
cout<<endl<<"\t---------------------------------------------                       --------------"<<endl;
cout<<"\t|Customer id | Arrival Time | Service Time |                        Waiting Time |"<<endl;
cout<<"\t---------------------------------------------------                  --------"<<endl;
w[1]=0;
for(i=1; i<=n; i++)
{
w[i+1]=w[i]+s[i]-a[i+1];
cout<<"\t|\t"<<i<<"    |\t   "<<a[i]<<"\t    |\t"                           <<s[i]<<"\t   |\t"<<w[i]<<"\t  |"<<endl;
wa+=w[i];
}
cout<<"\t---------------------------------------------------                 --------"<<endl<<endl;
cout<<"Average waiting time = "                                             <<wa/n<<endl<<endl<<endl<<endl;
system("pause");
return 0;
}

Output:


No comments:

Post a Comment