我想爲銀行隊列創建一個C++程序。每3分鐘一個新客戶進入隊列。每個客戶需要5分鐘的時間進行服務。該程序打印出的信息,第30分鐘任何方式來同時運行2個循環?
- 後抵達的爲每一位客戶
- 讓每個客戶
- 有多少客戶是該行的時間的時間?
- 誰是當前服務客戶?
我寫當前代碼:
#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分鐘內發生的事件。 – imran 2014-10-17 13:22:11
如何做?你有建議的特定功能嗎? – 2014-10-17 13:34:21