日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

C++链式队列实现简易银行叫号系统

發布時間:2023/12/20 c/c++ 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C++链式队列实现简易银行叫号系统 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.實現功能

  • 用戶進入隊列排隊等待
  • 銀行窗口辦理業務
  • VIP客戶及公務客戶優先辦理
  • VIP及公務窗口閑置時可以為普通用戶辦理業務

2.注意

  • 為節約空間,僅在博客中提供部分代碼
  • 本程序采用手動運行方式而非隨時間自動運行,不過很容易就可以改成自動運行

3.代碼部分

#include<iostream> #include<windows.h> #include<conio.h>using namespace std;int alltime=0; //程序總運行時間struct Node{int data;Node *next; }; class Lqueue{ //采用鏈式隊列private:Node *front,*rear;int time;public:int len=0;Lqueue(){front=rear=NULL;time=0;}bool enqueue(int num);bool dequeue(int &num);void clear();void show();~Lqueue(){clear();} }; //鏈式隊列函數實現很容易,就不貼出來了

以下為用戶類的定義及三種用戶的定義

class User{public:int type;int waittime; //等待時間 int sertime=0; //已服務時間 int id=0; //用戶編碼 }; class Nuser:public User{ //Normal User public:Nuser(){type=1;waittime=0;sertime=0; } };class Vuser:public User{ //VIP Userpublic:Vuser(){type=2;waittime=0;sertime=0; } };class Ouser:public User{ //公務客戶public:Ouser(){type=3;waittime=0;sertime=0; } };

以下為銀行窗口類及三種不同窗口

class Bankwindow{public:int full=0;//0為空,1為滿 int start=0; //start=0表示未開始服務,=1表示開始服務 int starttime=0;int servetime(); //返回辦理業務所用時間 void serve(); //辦理業務 };void Bankwindow::serve(){int nowtime=0;nowtime=alltime;if(full==1&&start==0){starttime=alltime;start=1;}if(nowtime-starttime==4){full=0;start=0; } } class Nwindow:public Bankwindow{public:int num; //窗口編號 int cid; //客戶編號 char type; //客戶種類 };class Vwindow:public Bankwindow{public:int cid;char type; };class Owindow:public Bankwindow{public:int cid;char type; };

以下為模擬器類,程序主要在這里運行

class Simulater{ //模擬器類private:int time; Lqueue n,v,o;public:Nuser nu[30]; //假設有30個普通用戶Vuser vu[10]; //10個VIPOuser ou[10]; //10個公務int nnum=0,vnum=0,onum=0; //三種客戶中已服務的人數int runstart=0; //運行啟動 Nwindow nw[3]; //有三個普通窗口,一個VIP,一個公務,與人數對應Vwindow vw;Owindow ow;void setwindow(); //初始化窗口void idset(); //設定不同user的id void settype(int num); //輸入一個數字,根據數據來生成不同用戶 void enterque(Nuser nu); //用戶入隊 void enterque(Vuser vu);void enterque(Ouser ou);void callcustomer(); //叫號 void show(); //顯示銀行當前狀態void runtime(); //控制運行時間bool run(); //運行主函數 }; void Simulater::setwindow(){ //最開始所有窗口都為空nw[0].cid=0;nw[0].type=' ';nw[1].cid=0;nw[1].type=' ';nw[2].cid=0;nw[2].type=' ';vw.cid=0;vw.type=' ';ow.cid=0;ow.type=' '; }void Simulater::idset(){ //分別設定所有用戶的idfor(int i=0;i<30;i++){nu[i].id=i+1;}for(int j=0;j<10;j++){vu[j].id=j+1;}for(int k=0;k<10;k++){ou[k].id=k+1;}for(int o=0;o<3;o++){nw[o].num=o+1; //窗口號從一開始 } } // 由于程序是手動按周期執行的,所以用輸入零代表沒有用戶入隊 void Simulater::settype(int num){ //1為普通用戶,2為vip,3為公務 switch(num){case 0: //輸入0代表不添加客戶,即本周期為空break;case 1:enterque(nu[nnum]);break;case 2:enterque(vu[vnum]);break;case 3:enterque(ou[onum]);break;default:break;} } //普通用戶進隊,另兩種同理 void Simulater::enterque(Nuser nu){ //1:普通 2:VIP 3:公用 n.enqueue(nu.id);nnum++; }

以下為叫號函數

void Simulater::callcustomer(){int id;if(nw[0].full==0||nw[1].full==0||nw[2].full==0){ //先遍歷三個普通窗口if(nw[0].full==0&&n.len>0){ //當窗口為空且有人排隊時叫號n.dequeue(id);nw[0].type='n';nw[0].cid=id;nw[0].full=1;} if(nw[0].full==0&&n.len==0){ //沒人時清空nw[0].type=' ';nw[0].cid=0;}//另兩個普通窗口同理if(vw.full==0){ //VIP為空,VIP優先,然后再處理普通用戶if(v.len!=0){v.dequeue(id);vw.type='v';vw.cid=id; vw.full=1;}else if(v.len==0&&n.len!=0){n.dequeue(id);vw.type='n';vw.cid=id;vw.full=1;}else if(v.len==0&&n.len==0){vw.type=' ';vw.cid=0;}}//公務窗口和VIP同理 } void Simulater::show(){ //界面函數cout<<"當前用時"<<alltime<<endl; cout<<"普通窗口一號 普通窗口二號 普通窗口三號 VIP窗口 公務窗口"<<endl; //間隔兩個空格 cout<<" "<<nw[0].type<<nw[0].cid<<" "<<nw[1].type<<nw[1].cid<<" "<<nw[2].type<<nw[2].cid;cout<<" "<<vw.type<<vw.cid<<" "<<ow.type<<ow.cid<<endl; cout<<endl;cout<<endl;cout<<"普通用戶排隊人數:"<<n.len<<" "<<"VIP用戶排隊人數"<<v.len<<" "<<"公務用戶排隊人數"<<o.len<<endl;cout<<"請輸入進入隊列的用戶種類"<<endl; } void Simulater::runtime(){ //運行函數alltime++; } bool Simulater::run(){int num;if(runstart==0){setwindow();enterque(nu[0]); //先使每個窗口都進入一個客戶enterque(nu[1]);enterque(nu[2]);enterque(vu[0]);enterque(ou[0]);runstart=1;}callcustomer();show();nw[0].serve();nw[1].serve();nw[2].serve();vw.serve();ow.serve();num=getch()-48; //每周期只能進入一位客戶,每四個周期處理完一個客戶,輸入0則沒有客戶入隊settype(num);runtime();system("cls"); if(n.len!=0||v.len!=0||o.len!=0||nw[0].full!=0||nw[1].full!=0||nw[2].full!=0||vw.full!=0||ow.full!=0){ return true;} else{return false;}//如果全部處理完則結束,否則繼續處理 }

主函數

int main(){Simulater s;s.idset();while(s.run()!=0);return 0; }

4.測試

初始界面

運行界面
當VIP和公務空閑時會處理普通用戶

總結

以上是生活随笔為你收集整理的C++链式队列实现简易银行叫号系统的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。