【发布时间】:2014-12-13 02:02:51
【问题描述】:
我想为银行队列创建一个 C++ 程序。每 3 分钟就有一位新客户进入队列。每个客户需要 5 分钟的服务时间。程序在前 30 分钟后打印出信息
- 每位顾客的到达时间
- 每位顾客的离开时间
- 有多少客户在排队?
- 当前的服务客户是谁?
我写了当前的代码:
#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;
}
当前代码逐行执行;在队列循环完成之前,客户不会被转移到服务中。 要调整时间,我必须同时运行两个循环。这样客户在服务其他客户的同时进入队列
有什么建议吗?
【问题讨论】:
-
您的程序将实时运行(30 分钟)?您可能需要重新考虑这一点,以便您的程序可以在不到一秒的时间内模拟将在 30 分钟内发生的事件。
-
怎么做?你有什么具体的建议吗?
标签: c++ loops queue sleep ctime