📄 bank.cpp
字号:
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include"bank.h"
void PrintDLList(Bank *B)
{
int n,i;
Event en;
n=(B->L).Size();
for(i=0;i<n;i++)
{
en=(B->L).GetData(i);
cout<<setw(4)
<<"("
<<setiosflags(ios::left)
<<setw(4)<<en.occurtime
<<resetiosflags(ios::left)
<<setw(4)<<en.ntype
<<")"
<<endl;
}
}
void PrintLQueue(Bank *B)
{
int i,k,n;
Service cn;
for(i=0;i<4;i++)
{
cout<<i;
n=(B->Q[i]).Size();
for(k=0;k<n;k++)
{
cn=(B->Q[i]).Delete();
cout<<setw(3)
<<"("
<<setiosflags(ios::left)
<<setw(4)<<cn.arrivaltime
<<resetiosflags(ios::left)
<<setw(4)<<cn.servicetime
<<")"
<<endl;
(B->Q[i]).Insert(cn);
}
cout<<endl;
}
}
void main(void)
{
int intertime,servicetime;
Event en;
Bank B(20);
cout<<endl<<"Open for day"<<endl;
cout<<"event list"<<endl;
PrintDLList(&B);
cout<<"queue list"<<endl;
PrintLQueue(&B);
cout<<"Press any key and simulation continues."<<endl<<endl;
getch();
while(!B.Empty())
{
en=B.Customer();
if(en.ntype==-1)
{
servicetime=3+rand()%10; //3+random(10);
intertime=1+rand()%5; //1+random(5);
B.CustomerArrived(en,servicetime,intertime);
cout<<"One customer arrived"<<endl;
cout<<setiosflags(ios::left)
<<setw(8)<<en.occurtime
<<resetiosflags(ios::left)
<<setw(5)<<en.ntype
<<endl;
cout<<"servicetime intertime"<<endl;
cout<<setiosflags(ios::left)
<<setw(8)<<servicetime
<<resetiosflags(ios::left)
<<setw(5)<<intertime
<<endl;
cout<<"event list"<<endl;
PrintDLList(&B);
cout<<"queue list"<<endl;
PrintLQueue(&B);
cout<<"Press any key and simulation continues."<<endl
<<endl;
getch();
}
else
{
B.CustomerDeparture(en);
cout<<"One customer left"<<endl;
cout<<setiosflags(ios::left)
<<setw(8)<<en.occurtime
<<resetiosflags(ios::left)
<<setw(5)<<en.ntype
<<endl;
cout<<"event list"<<endl;
PrintDLList(&B);
cout<<"queue list"<<endl;
PrintLQueue(&B);
cout<<"Press any key and simulation continues."<<endl
<<endl;
getch();
}
}
cout<<"totaltime"<<setw(6)<<B.totaltime<<endl;
cout<<"cusnum"<<setw(9)<<B.cusnum<<endl;
cout<<"The average time is"<<setw(4)<<B.totaltime/B.cusnum<<endl;
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -