#include "stdafx.h"#include #include #include #include #include #define MAX_SIZE 500struct tagCustom{ int m_nID; // 客户的编号 int m_nProcessTime; // 需要处理业务的时间 int m_nArrivalTime; // 到达时间 int m_nDepartTime; // 离开时间};struct tagTeller{ int m_nCustomNum; // 处理的客户数 int m_nAllServiceTime; // 所有服务时间 int m_nFinishServiceTime; // 柜台针对一个客户服务的结束时间 bool m_bBusy; // 柜台是否忙 int m_nCustomID; // 正在服务的客户的ID号};tagTeller g_aryTellers[MAX_SIZE];int g_nTellerNum; // 柜台数量// 用户到达数组(随机的,无序的)tagCustom g_aryAllCustoms[MAX_SIZE];int g_nCustomsNum;int g_nWorkTime; // 经营时间int g_nArrivalRange,g_nServiceRange;// 用户队列tagCustom g_CustomQueue[MAX_SIZE];int g_nHeader,g_nTail;// 队列的操作void InitQueue(){ g_nHeader = g_nTail = -1; }void AddToTail(tagCustom aCustom){ g_nTail++; g_CustomQueue[g_nTail] = aCustom; }bool RemoveFromHeader(tagCustom* pCustom){ if(g_nHeader < g_nTail) { g_nHeader++; (*pCustom) = g_CustomQueue[g_nHeader]; return true; } return false;}// 功能:模拟用户的随机到来void GenerateCustom(){ tagCustom aCustom; for(int nCounter = 0; nCounter < g_nCustomsNum; nCounter++) { aCustom.m_nID = nCounter; aCustom.m_nArrivalTime = rand() % g_nWorkTime ; aCustom.m_nProcessTime = (rand() % g_nServiceRange + 1) * 6; aCustom.m_nDepartTime = -1; g_aryAllCustoms[nCounter] = aCustom; }}void Init(){ g_nTellerNum = 3; g_nWorkTime = 200; g_nCustomsNum = 30; g_nArrivalRange = 18 ; g_nServiceRange = 5 ; srand((unsigned)time(NULL)); InitQueue(); GenerateCustom(); for(int nC = 0; nC < g_nTellerNum; nC++) { g_aryTellers[nC].m_nAllServiceTime = 0; g_aryTellers[nC].m_nCustomID = -1; g_aryTellers[nC].m_bBusy = false; g_aryTellers[nC].m_nFinishServiceTime = -1; }}