Simulation(inttellerNum,intsimuTime,intarrivalLow,intarrivalHigh,intserviceLow,intserviceHigh)
:tellerNum(tellerNum),simuTime(simuTime),arrivalLow(arrivalLow),arrivalHigh(arrivalHigh),
serviceLow(serviceLow),serviceHigh(serviceHigh),
arrivalRange(arrivalHigh-arrivalLow+1),serviceRange(serviceHigh-serviceLow+1)
{srand((unsigned)time(NULL));}
voidInitialize()
{
curTime=nextTime=0;
customerNum=customerTime=0;
for(inti=1;i<=tellerNum;i++)
{
tellers[i].totalCustomerCount=0;
tellers[i].totalServiceTime=0;
tellers[i].finishServiceTime=0;
}
customer.MakeEmp ty();
}
voidRun()
{
Initialize();
NextArrived();
#ifdefPRINTPROCESS
cout<
cout<<"tellerID";
for(intk=1;k<=tellerNum;k++)cout<<"\tTELLER"<
cout<
#endif
for(curTime=0;curTime<=simuTime;curTime++)
{
if(curTime>=nextTime)
{
CustomerArrived();
NextArrived();
}
#ifdefPRINTPROCESS
cout<<"Time:"<
#endif
for(inti=1;i<=tellerNum;i++)
{
if(tellers[i].finishServiceTime
if(tellers[i].finishServiceTime==curTime&&!customer.IsEmpty())
{
intt=NextService();
#ifdefPRINTPROCESS
cout<<'\t'<
#endif
CustomerDeparture();
tellers[i].totalCustomerCount++;
tellers[i].totalServiceTime+=t;
tellers[i].finishServiceTime+=t;
}
#ifdefPRINTPROCESS
elsecout<<"\t";
#endif
}
#ifdefPRINTPROCESS
cout<
#endif
}
PrintResult();
}
voidPtintSimuPara()
{
cout<
cout<<"柜臺數量:"<
cout<<"兩個顧客來到的最小間隔時間:"<
cout<<"兩個顧客來到的最大間隔時間:"<
cout<<"柜臺服務最短時間:"<
cout<<"柜臺服務最長時間:"<
}
voidPrintResult()
{
inttSN=0;
longtST=0;
cout<
cout<<"----模擬結果------";
cout<
for(inti=1;i<=tellerNum;i++)
{
cout<<"TELLER"<
cout<<'\t'<
cout<<'\t'<
cout<<'\t';
if(tellers[i].totalCustomerCount)
cout<<(flo at)tellers[i].totalServiceTime/(float)tellers[i].totalCustomerCount;
elsecout<<0;
cout<<""<
}
cout<<"TOTAL\t"<
if(tSN)cout<<(float)tST/(float)tSN;elsecout<<0;
cout<<""<
cout<<"CustomerNumber:\t"<
cout<<"CustomerWaitTime:\t"<
if(tSN)cout<<(float)customerTime/(float)tSN;elsecout<<0;
cout<
}
private:
inttellerNum;
intsimuTime;
intcurTime,nextTime;
intcustomerNum;
longcustomerTime;
intarrivalLow,arrivalHigh,arrivalRange;
intserviceLow,serviceHigh,serviceRange;
Tellertellers[21];
Queuecustomer;
相關推薦:2010年9月計算機等級考試精華備考資料匯總北京 | 天津 | 上海 | 江蘇 | 山東 |
安徽 | 浙江 | 江西 | 福建 | 深圳 |
廣東 | 河北 | 湖南 | 廣西 | 河南 |
海南 | 湖北 | 四川 | 重慶 | 云南 |
貴州 | 西藏 | 新疆 | 陜西 | 山西 |
寧夏 | 甘肅 | 青海 | 遼寧 | 吉林 |
黑龍江 | 內蒙古 |