#include<iostream>
#include<queue>
#include<cstdlib>
#include<ctime>
using namespace std;
class Customer
{
private :
long arrive;
int processtime;
public:
Customer(){arrive=processtime=0;}
void set(long when){
processtime=rand()%3+1;
arrive =when;
}
long when ()const{
return arrive;
}
int ptime()
{
return processtime;
}
friend ostream& operator<<(ostream &os,const Customer &c)
{
static int j=0;
os<<j++<<" arrive: "<<c.arrive<<" need time: "<<c.processtime<<endl;
return os;
}
};
typedef Customer Item;
const int MIN_PER_HR =60;
bool newCustomer(double x)
{
return rand()*x/RAND_MAX<1;
}
void main()
{
srand(time(0));
cout<<"Case Study :Bank of Heather Automatic Teller"<<endl;
cout<<"enter maximun size of queue: ";
int qs;
cin>>qs;
queue<Item>line;
cout <<"enter the number of simulation hours : ";
int hours;
cin>>hours;
long cyclelimit =MIN_PER_HR*hours;
cout<<"enter the average number of customer per hour: ";
double perhour;
cin>>perhour;
double min_per_cust;
min_per_cust=MIN_PER_HR/perhour;
Item temp;
long turnaways=0;
long customers=0;
long served=0;
long sum_line=0;
int wait_time =0;
long line_wait=0;
for(int cycle=0;cycle<cyclelimit;cycle++)
{
if(newCustomer(min_per_cust))
{
if(line.size()==qs)
turnaways++;
else
{
customers++;
temp.set(cycle);
line.push(temp);
}
}
if(wait_time<=0&&line.size()!=0)
{
line.pop();
wait_time =temp.ptime();
line_wait+=cycle -temp.when();
served++;
}
if(wait_time>0)
wait_time--;
sum_line +=line.size();
}
if(customers>0)
{
cout<<"customers accepted:"<<customers<<endl;
cout<<" coutomers served: "<<served<<endl;
cout<<" turnaways: "<<turnaways<<endl;
cout<<"average queue size: ";
cout.precision(2);
cout.setf(ios_base::fixed,ios_base::floatfield);
cout<<(double)sum_line/cyclelimit<<endl;
cout<<"average wait time: "<<(double)line_wait/served<<" minutes"<<endl;
}
else
cout<<" no coustomer!"<<endl;
cout<<"done!"<<endl;
system("pause");
}
#include<queue>
#include<cstdlib>
#include<ctime>
using namespace std;
class Customer
{
private :
long arrive;
int processtime;
public:
Customer(){arrive=processtime=0;}
void set(long when){
processtime=rand()%3+1;
arrive =when;
}
long when ()const{
return arrive;
}
int ptime()
{
return processtime;
}
friend ostream& operator<<(ostream &os,const Customer &c)
{
static int j=0;
os<<j++<<" arrive: "<<c.arrive<<" need time: "<<c.processtime<<endl;
return os;
}
};
typedef Customer Item;
const int MIN_PER_HR =60;
bool newCustomer(double x)
{
return rand()*x/RAND_MAX<1;
}
void main()
{
srand(time(0));
cout<<"Case Study :Bank of Heather Automatic Teller"<<endl;
cout<<"enter maximun size of queue: ";
int qs;
cin>>qs;
queue<Item>line;
cout <<"enter the number of simulation hours : ";
int hours;
cin>>hours;
long cyclelimit =MIN_PER_HR*hours;
cout<<"enter the average number of customer per hour: ";
double perhour;
cin>>perhour;
double min_per_cust;
min_per_cust=MIN_PER_HR/perhour;
Item temp;
long turnaways=0;
long customers=0;
long served=0;
long sum_line=0;
int wait_time =0;
long line_wait=0;
for(int cycle=0;cycle<cyclelimit;cycle++)
{
if(newCustomer(min_per_cust))
{
if(line.size()==qs)
turnaways++;
else
{
customers++;
temp.set(cycle);
line.push(temp);
}
}
if(wait_time<=0&&line.size()!=0)
{
line.pop();
wait_time =temp.ptime();
line_wait+=cycle -temp.when();
served++;
}
if(wait_time>0)
wait_time--;
sum_line +=line.size();
}
if(customers>0)
{
cout<<"customers accepted:"<<customers<<endl;
cout<<" coutomers served: "<<served<<endl;
cout<<" turnaways: "<<turnaways<<endl;
cout<<"average queue size: ";
cout.precision(2);
cout.setf(ios_base::fixed,ios_base::floatfield);
cout<<(double)sum_line/cyclelimit<<endl;
cout<<"average wait time: "<<(double)line_wait/served<<" minutes"<<endl;
}
else
cout<<" no coustomer!"<<endl;
cout<<"done!"<<endl;
system("pause");
}