1、.#include #include #include #include using namespace std;class userpublic:int id;int iswait;int arrivetime;int servetime;void getserve()iswait = 0;user(int d=0,int s=1,char ty=NULL)id=d;iswait=s;type=ty;servetime=4;char type;class nuser:public userpublic:nuser(int d=0,int s=1,char ty=n):user(d,s,ty)
2、;class vuser:public userpublic:vuser(int d=0,int s=1,char ty=v):user(d,s,ty);class ouser:public userpublic:ouser(int d=0,int s=1,char ty=o):user(d,s,ty);class bankwindowpublic:bool isbuy;.int id;user client;char type;bankwindow(int d=0,bool is=1,char ty=NULL ):client(0,1,NULL)id=d;isbuy =is;type=ty;
3、void handleuser()isbuy=0;class nwindow:public bankwindowpublic:nwindow(int d=0,bool is=0,char ty=n):bankwindow(d,is,ty);class vwindow:public bankwindowpublic:vwindow(int d=0,bool is=0,char ty=v):bankwindow(d,is,ty);class owindow:public bankwindowpublic:owindow(int d=0,bool is=0,char ty=o):bankwindow
4、(d,is,ty);class simpublic:queue nuqueue;queue vuqueue;queue ouqueue;nwindow nw3;vwindow vw;owindow ow;static int j;static int m;static int g;void userenter();void simuserenter();void calluser();.void simu();void handle()for(int i=0;i3;i+)nwi.handleuser();ow.handleuser();vw.handleuser();int sim:j=1;i
5、nt sim:m=1;int sim:g=1;void sim:simuserenter()nuser *n;vuser *v;ouser *o;for(int i=0;iid=j;j+;nuqueue.push(*n);v=new vuser;v-id=g;g+;vuqueue.push(*v);o=new ouser;o-id=m;m+;ouqueue.push(*o);void sim:calluser()int i;for(i=0;i3;i+)if(!nuqueue.empty()&nwi.isbuy=0)nwi.isbuy=1;nwi.type=nuqueue.front().typ
6、e;nwi.id=nuqueue.front().id;nuqueue.pop();.if(!vuqueue.empty()&vw.isbuy=0)vw.isbuy=1;vw.type=vuqueue.front().type;vw.id=vuqueue.front().id;vuqueue.pop();else if(vuqueue.empty()&vw.isbuy=0&!nuqueue.empty()vw.isbuy=1;vw.type=nuqueue.front().type;vw.id=nuqueue.front().id;nuqueue.pop();if(!ouqueue.empty
7、()&ow.isbuy=0)ow.isbuy=1;ow.type=ouqueue.front().type;ow.id=ouqueue.front().id;ouqueue.pop();else if(ouqueue.empty()&ow.isbuy=0&!nuqueue.empty()ow.isbuy=1;ow.type=nuqueue.front().type;ow.id=nuqueue.front().id;nuqueue.pop();void sim:userenter()int i;for(i=0;i3;i+)if(nwi.isbuy=1)cout 普通 i+1 窗口正在服务 nwi
8、.typenwi.id顾客! n;elsecout 普通 i+1 窗口空闲!n;if(vw.isbuy=1)cout VIP 窗口正在服务vw.type vw.id 顾客! n;else.cout VIP 窗口空闲! n;if(ow.isbuy=1)cout 对公窗口正在服务ow.typeow.id 顾客! n;elsecout 对公窗口空闲! !n;if(!nuqueue.empty()cout 普通顾客还有nuqueue.size()人在等候! endl;elsecout 普通顾客已经无人等待!endl;if(!vuqueue.empty()coutVIP 顾客还有vuqueue.size
9、()人在等候! endl;elsecoutVIP 顾客已经无人等待!endl;if(!ouqueue.empty()cout 对公顾客还有ouqueue.size()人在等候! endl;elsecout 对公顾客已经已经无人等待!endl;void sim:simu()long t1,t2;simuserenter();t1=time(0);t2=time(0);while(1)coutendl 营业开始 10e-6)t2=time(0);coutendl 第二秒 10e-6)t2=time(0);coutendl 第四秒 10e-6)t2=time(0);coutendl 第六秒 10e-6)t2=time(0);coutendl 第八秒 10e-6)t2=time(0);coutendl 营业结束 endl;handle();calluser();userenter();break;int main()sim s;s.simu();return 0;.