您好,欢迎访问三七文档
当前位置:首页 > 财经/贸易 > 资产评估/会计 > 银行排号系统完整C++代码
#includeiostream#includequeue#includectime#includecmathusingnamespacestd;classuser{public:intid;intiswait;intarrivetime;intservetime;voidgetserve(){iswait=0;}user(intd=0,ints=1,charty=NULL){id=d;iswait=s;type=ty;servetime=4;}chartype;};classnuser:publicuser{public:nuser(intd=0,ints=1,charty='n'):user(d,s,ty){}};classvuser:publicuser{public:vuser(intd=0,ints=1,charty='v'):user(d,s,ty){}};classouser:publicuser{public:ouser(intd=0,ints=1,charty='o'):user(d,s,ty){}};classbankwindow{public:boolisbuy;intid;userclient;chartype;bankwindow(intd=0,boolis=1,charty=NULL):client(0,1,NULL){id=d;isbuy=is;type=ty;}voidhandleuser(){isbuy=0;}};classnwindow:publicbankwindow{public:nwindow(intd=0,boolis=0,charty='n'):bankwindow(d,is,ty){}};classvwindow:publicbankwindow{public:vwindow(intd=0,boolis=0,charty='v'):bankwindow(d,is,ty){}};classowindow:publicbankwindow{public:owindow(intd=0,boolis=0,charty='o'):bankwindow(d,is,ty){}};classsim{public:queuenusernuqueue;queuevuservuqueue;queueouserouqueue;nwindownw[3];vwindowvw;owindowow;staticintj;staticintm;staticintg;voiduserenter();voidsimuserenter();voidcalluser();voidsimu();voidhandle(){for(inti=0;i3;i++)nw[i].handleuser();ow.handleuser();vw.handleuser();}};intsim::j=1;intsim::m=1;intsim::g=1;voidsim::simuserenter(){nuser*n;vuser*v;ouser*o;for(inti=0;i5;i++){n=newnuser;n-id=j;j++;nuqueue.push(*n);}v=newvuser;v-id=g;g++;vuqueue.push(*v);o=newouser;o-id=m;m++;ouqueue.push(*o);}voidsim::calluser(){inti;for(i=0;i3;i++){if(!nuqueue.empty()&&nw[i].isbuy==0){nw[i].isbuy=1;nw[i].type=nuqueue.front().type;nw[i].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();}elseif(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()&&ow.isbuy==0){ow.isbuy=1;ow.type=ouqueue.front().type;ow.id=ouqueue.front().id;ouqueue.pop();}elseif(ouqueue.empty()&&ow.isbuy==0&&!nuqueue.empty()){ow.isbuy=1;ow.type=nuqueue.front().type;ow.id=nuqueue.front().id;nuqueue.pop();}}voidsim::userenter(){inti;for(i=0;i3;i++){if(nw[i].isbuy==1)cout普通i+1窗口正在服务nw[i].typenw[i].id顾客!\n;elsecout普通i+1窗口空闲!!\n;}if(vw.isbuy==1)coutVIP窗口正在服务vw.typevw.id顾客!\n;elsecoutVIP窗口空闲!!\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()人在等候!endl;elsecoutVIP顾客已经无人等待!endl;if(!ouqueue.empty())cout对公顾客还有ouqueue.size()人在等候!endl;elsecout对公顾客已经已经无人等待!endl;}voidsim::simu(){longt1,t2;simuserenter();t1=time(0);t2=time(0);while(1){coutendl营业开始endl;calluser();userenter();while(fabs(t2-t1-2)10e-6){t2=time(0);}coutendl第二秒endl;simuserenter();calluser();userenter();while(fabs(t2-t1-4)10e-6){t2=time(0);}coutendl第四秒endl;handle();calluser();userenter();while(fabs(t2-t1-6)10e-6){t2=time(0);}coutendl第六秒endl;simuserenter();userenter();while(fabs(t2-t1-8)10e-6){t2=time(0);}coutendl第八秒endl;handle();calluser();userenter();while(fabs(t2-t1-12)10e-6){t2=time(0);}coutendl营业结束endl;handle();calluser();userenter();break;}}intmain(){sims;s.simu();return0;}
本文标题:银行排号系统完整C++代码
链接地址:https://www.777doc.com/doc-6965586 .html