I want to create a c++ program for a bank queue. Where every 3 minutes a new customer enters the queue. every customer needs 5 minutes for the service. The program print out the information after the first 30 minutes
- The time of arriving for each customer
- The time of leaving for each customer
- How many customers are in the line?
- Who is the current serving customer?
I wrote the current code:
#include <queue>
#include <ctime>
#include <time.h>
#include <conio.h>
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
queue <int> inq;
queue <int> inservice;
int z= 1;
for(int i=0; i<=9; i++)
{
inq.push(z);
Sleep(180000);
_strtime_s(hold_time);
cout<<"Time of arriving for customer number "<<z<<" is: "<<hold_time<<endl;
z++;
}
do
{
inservice.push(inq.front());
Sleep(300000);
_strtime_s(hold_time);
cout<<"Time of leaving for customer number "<<z<<" is: "<<hold_time<<endl;
inq.pop();
}
while(!inq.empty());
cout<<"number of customers waiting : "<<inq.size()<<endl;
cout<<"Customer number "<<inservice.front()<< " is currently serving"<<endl;
return 0;
}
The current code executes line by line; customers will not be moved to service until the queue loop is done. To adjust time, I have to run the two loops at the same time. such that customers enter the queue at the same time other costumers are being served
Any suggestions ?