生活随笔
收集整理的這篇文章主要介紹了
基于链队列的银行叫号系统
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
程序所能達到的功能:
可視化操作界面。客戶和工作人員共用同一個虛擬隊列,客戶取編號后的信息及時更新給工作人員。VIP客戶和普通客戶有設立不同窗口派號功能:客戶可根據自己的情況進行操作領取編號,同時可知道當前有多少人正在排隊。叫號功能:工作人員通過客戶的排隊情況進行叫號,在顯示器上顯示出來。以及其他相關的人性化設計輔助功能
#define _CRT_SECURE_NO_WARNINGS
/* Bank System */#include<ctime>
#include "queue.h"
#include<windows.h>
#define VIP 0
#define COMMON 1
#define WORKER 1
#define CLIENT 0
time_t now;/*系統時間*///#include "queue_queue.h"//#define Line_ModeLinkQueue *common, *vip;//對象/* printf_func */
void printf_func(int flag)
{system("cls");if (flag) {printf(" *╭╮ ╭╮ ╭╮ \n");printf(" ││ ││ │└ ╮ \n ");printf(" ╭ ┴┴ ─ ┴┴Ⅲ ╮ ~└─ ╯ \n");printf(" | ﹋ ﹋ | ------------------------------ \n");printf(" | ∩ ∩ | ○ ☆ 請根據具體情況進行選擇哦!☆ \n");printf(" | ▽ | O ------------------------------- \n");printf(" ╰ ─ m∞m─ ╯ \n");printf("\n\n -------------------------------------------------------\n ");printf(" | 中文 English | \n"); printf(" |1.呼叫vip用戶的編號------One.Back call VIP number | \n");//呼叫的號碼printf(" |2.呼叫普通用戶的編號-----Two.Back call COMMON number | \n");//呼叫的號碼printf(" |3.結束-------------------Three.Exit | \n");//通道printf(" ------------------------------------------------------ \n");printf("\n 請選擇[1-3]--------------Please Select[one-three]:");//選擇1-3窗口}else {printf(" *╭╮ ╭╮ ╭╮ \n");printf(" ││ ││ │└ ╮ \n ");printf(" ╭ ┴┴ ─ ┴┴Ⅲ ╮ ~└─ ╯ \n");printf(" | ﹋ ﹋ | ------------------------------ \n");printf(" | ∩ ∩ | ○ ☆ 請根據你的情況進行選擇哦!☆ \n");printf(" | ▽ | O ------------------------------- \n");printf(" ╰ ─ m∞m─ ╯ \n");printf("\n\n --------------------------------------------------\n");printf(" | 中文 English |\n"); printf(" | 1.vip用戶獲取號----One.vip user get number | \n");printf(" | 2.普通用戶獲取號---Two.common user get number | \n");printf(" | 3.結束------------Three.Exit | \n");//結束的通道printf(" -------------------------------------------------- \n");printf("\n 請選擇[1-3]:--------Please Select[one-three]:");//選擇1-3窗口}
}/*
select_num
*/
int select_num(int flag)
{int num = 0;while (num < 1 || num > 3){printf_func(flag);scanf("%d", &num);}return num;
}/*
* Bank System Init 初始化
*/
int Bank_Sys_Init(void)
{vip = new LinkQueue;common = new LinkQueue;InitQueue(*vip);InitQueue(*common);return 0;
}/*
Bank System Quit退出程序
*/
int Bank_Sys_Term(void)
{DestoryQueue(*vip);DestoryQueue(*common);return 0;
}/*
Bank Get One ID
*/
int Bank_Sys_Get_Id(int flag)
{static int vip_id = 0;static int common_id = 0;//Line Modeif (flag == 0){if (0 == EnQueue(*vip, vip_id)){vip_id++;return vip_id;}elsereturn -1;}else{if (0 == EnQueue(*common, common_id)){common_id++;return common_id;}elsereturn -1;}}/***************************************************************
* Bank Call One ID
****************************************************************/
int Bank_Sys_Call_Id(int flag)
{int id, state;if (!flag) {state = DeQueue(*vip, id);}else {state = DeQueue(*common, id);}if (state == -1)return -1;return id;
}/***************************************************************
* Bank Get All Users Number
****************************************************************/
unsigned int Bank_Get_User_Num(int flag)
{unsigned int num;if (flag == 0)num = getLeft(*vip);//獲得隊列的長度elsenum = getLeft(*common);return num;
}
//bank--logo
void User_dispaly()
{printf("\n\n");printf(" 謝謝您的使用,歡迎下次再來!\n");printf("-------------------------------< bank--logo >---------------------------------\n\n");printf(" ``╭╮ ╭╮ ╭╮\n");printf(" ``││ ││ │└ ╮ \n");printf(" ╭┴┴———————┴┴╮~└—╯\n");printf(" │ │\n");printf(" │ ● ● │ \n");printf(" │ ○ ○│ \n");printf(" │ ╰—╯ │ \n");printf(" │ │ \n");printf(" ╰—┬o— — —o┬—╯ \n");printf(" ╭╮努力╭╮ \n");printf(" ╰┴————┴╯ \n");printf(" ══════════════════ \n");printf(" ║ 韶關學院銀行 ║ \n");printf(" ║ 制作:陳玲瓏 ║ \n");
}
void Worker_dispaly()
{printf("\n\n");printf(" 辛苦您啦,下次再見!\n");printf("-------------------------------< bank--logo >---------------------------------\n\n");printf(" ``╭╮ ╭╮ ╭╮\n");printf(" ``││ ││ │└ ╮ \n");printf(" ╭┴┴———————┴┴╮~└—╯\n");printf(" │ │\n");printf(" │ ● ● │ \n");printf(" │ ○ ○│ \n");printf(" │ ╰—╯ │ \n");printf(" │ │ \n");printf(" ╰—┬o— — —o┬—╯ \n");printf(" ╭╮努力╭╮ \n");printf(" ╰┴————┴╯ \n");printf(" ══════════════════ \n");printf(" ║ 韶關學院銀行 ║ \n");printf(" ║ 制作:陳玲瓏 ║ \n");
}
void introduce() {printf("\n 韶關學院銀行系統啟動中…… \n\n");Sleep(1000);system("cls");printf(" ``╭╮ ╭╮ ╭╮ \n");printf(" ``││ ││ │└ ╮ ∩------------------------------∩ \n");printf(" ╭┴┴———————┴┴╮~└—╯ | 您好,請根據您的需求進行操作,| \n");printf(" │ │ | 小白將會為您服務! | \n");printf(" │ ● ● │ ○ ∪------------------------------∪ \n");printf(" │ ○ ○│ ○ \n");printf(" │ ╰—╯ │ \n");printf(" │ │ \n");printf(" ╰—┬o— — —o┬—╯\n");printf(" ╭╮小白╭╮\n");printf(" ╰┴————┴╯\n");
}int login() {FILE *fp1, *fp2;int state;char str1[20], str2[20], str_z[20], str_m[20];//printf(" now time is %s\n", ctime(&now));//introduce();if ((fp1 = fopen("admin.txt", "rb")) == NULL){introduce();printf("\n 韶關學院銀行歡迎您的使用! \n\n");printf(" -------------------------創建管理員賬號----------------------\n");printf(" | 本系統沒有您的工作后,請創建! |\n");printf(" -------------------------------------------------------------\n");now = time(NULL);printf(" Now time is %s\n", ctime(&now));printf(" -------------------------------------------------------------\n");printf(" ☆ 請輸入管理員賬號:");scanf("%s", str_z);printf(" ☆ 請輸入密碼: ");scanf("%s", str_m);printf(" -------------------------------------------------------------\n");fp2 = fopen("admin.txt", "wb");fprintf(fp2, "%s%c", str_z, '\n');fprintf(fp2, "%s%c", str_m, ' ');fclose(fp2);}fp1 = fopen("admin.txt", "rb");fscanf(fp1, "%s", str1);fscanf(fp1, "%s", str2);fclose(fp1);while (1){system("cls");introduce();printf("\n 韶關學院銀行歡迎您的使用! \n\n");printf(" ----------------------------使用方式-------------------------\n");printf(" | |\n");printf(" | 1.工作人員模式 0.用戶模式 |\n");printf(" | One.Worker mode zero.user mode |\n");printf(" -------------------------------------------------------------\n");now = time(NULL);printf(" Now time is %s\n", ctime(&now));printf(" -------------------------------------------------------------\n");printf(" * 請你選擇(0-1):");scanf("%d", &state);printf(" -------------------------------------------------------------\n");if (state == 0)return 0;else if (state == 1){system("cls");printf(" *╭╮ ╭╮ ╭╮ \n");printf(" ││ ││ │└ ╮ \n ");printf(" ╭ ┴┴ ─ ┴┴Ⅲ ╮ ~└─ ╯ \n");printf(" | ﹋ ﹋ | ------------------------------------- \n");printf(" | ∩ ∩ | ○ ☆用您的專屬工號進行登錄才能工作哦!☆ \n");printf(" | ▽ | O ------------------------------------- \n");printf(" ╰ ─ m∞m─ ╯ \n");//printf("\n ------------------------------------------------------------ \n");printf(" → 請輸入賬號:");scanf("%s", str_z);printf(" → 請輸入密碼:");scanf("%s", str_m);printf(" -------------------------------------------------------------\n");if (strcmp(str1, str_z) == 0 && strcmp(str2, str_m) == 0){getchar();getchar();return 1;}else{printf(" -------------------------------------------------------------\n");printf(" | 賬號或密碼錯誤!!! |\n");printf(" -------------------------------------------------------------\n");system("PAUSE");system("cls");}}else{printf(" -------------------------------------------------------------\n");printf(" | 輸入不合法!!! |\a \n");printf(" -------------------------------------------------------------\n");system("PAUSE");system("cls");}/*printf(" ."".????."". 您 \n");printf(" |??|???/??/ 已 \n");printf(" |??|??/??/ 成 \n");printf(" |??|?/??/ 功 \n");printf(" |??|/??;-._ 取 \n");printf(" }??`?_/??/?;? 編 \n");printf(" |??/`?)?/??/ 號 \n");printf(" | / / _/\_/\ , \n");printf(" |?/??/?????\ 請 \n");printf(" ( ' \ '- | 耐 \n");printf(" \ ` . / 心 \n");printf(" | | 等 \n");printf(" | | 候 \n");*/}
}
//選擇VIP窗口
int SelectVIPWindow() {printf("\n請輸入你所負責的窗口號:\n");printf("請選擇[1-2]:");//選擇1-2窗口int num;cin >> num;while (num < 1 || num>2) {printf("\n錯誤!!\n");printf("請再次輸入你所負責的窗口號:\n");printf("請選擇[1-2]:");//選擇1-2窗口cin >> num;}return num;
}int SelectCommonWindow() {printf("\n請輸入你所負責的窗口號:\n");printf("請選擇[3-10]:");//選擇1-4窗口int num;cin >> num;while (num < 3 || num>10) {printf("\n錯誤!!\n");printf("請再次輸入你所負責的窗口號:\n");printf("請選擇 [3-10]:");//選擇1-4窗口cin >> num;}return num;
}/***************************************************************
* main
****************************************************************/
int main(int argc, char**argv)
{int id, Vip;//id-用戶排隊號碼,vip-會員排隊號碼unsigned int num;//前面有num個人在排隊int role;role = login();system("cls");Bank_Sys_Init();//dispaly();if (role == WORKER) {//工作人員叫號while (1){switch (select_num(WORKER)){case 1:int VIPWindowNumber;//VIP窗口號VIPWindowNumber = SelectVIPWindow();Bank_Sys_Init();load(*vip, VIP);num = Bank_Get_User_Num(VIP);id = Bank_Sys_Call_Id(VIP);write(*vip, VIP);Bank_Sys_Term();if (id == -1)printf("\n沒有人在排隊---there are no people in wait\n\n");else{printf("\n您應該叫VIP %d 來窗口號 %d ------you should call VIP %d,and go to window %d\n", id + 1, VIPWindowNumber, id + 1, VIPWindowNumber);printf("現在有 %d 個人在排隊 ------there are %d people are in wait\n\n", num,num);system("pause");system("cls");printf("\n\n\n-----------------------------------------------------------------------------------------------------------\n");printf("/n請編號為%d的VIP客戶到%d窗口辦理業務!-------Customers numbered %d should go to %d window for business\n", id + 1, VIPWindowNumber, id + 1, VIPWindowNumber);printf("---------------------------------------------------------------------------------------------------------------\n");}break;case 2:int CommonWindowNumber;CommonWindowNumber = SelectCommonWindow();Bank_Sys_Init();load(*common, COMMON);num = Bank_Get_User_Num(COMMON);id = Bank_Sys_Call_Id(COMMON);write(*common, COMMON);Bank_Sys_Term();if (id == -1)printf("\n沒有人在排隊-----there are no people in wait\n\n");else{printf("\n您應該叫普通用戶 %d 來窗口 %d ----you should call COMMON %d,and go to window %d\n", id + 1, CommonWindowNumber, id + 1, CommonWindowNumber);printf("現在有 %d 個人在排隊-------there are %d people are in wait\n\n", num,num);system("pause");//-------------------------------------------------------------------------------system("cls");printf("\n\n\n");printf("-----------------------------------------------------------------------------------------------------------\n");printf("/n請編號為%d的VIP客戶到%d窗口辦理業務!-------Customers numbered %d should go to %d window for business\n", id + 1, CommonWindowNumber, id + 1, CommonWindowNumber);printf("---------------------------------------------------------------------------------------------------------------\n");}break;case 3:system("cls");Worker_dispaly();system("pause");Bank_Sys_Term();remove("VIP.txt");remove("COMMON.txt");return 0;}system("pause");}}else {//用戶while (1){switch (select_num(CLIENT)){case 1:{Bank_Sys_Init();load(*vip, VIP);id = Bank_Sys_Get_Id(VIP);num = Bank_Get_User_Num(VIP);write(*vip, VIP);Bank_Sys_Term();if (id == -1)printf("\n編號已經爆棚了,您需要等幾分鐘!-------the number is too large, you have to wait several minutes !\n");else{system("cls");printf("\n\n您的編號為.%d ----you get the vip %d\n", id, id);printf("現在有 %d 個人在您前面排隊--there are %d people in front of you\n\n", num - 1, num - 1);//------------------------------------------------------------------------------------------printf(" .''. .''. 您 \n");printf(" | | / / 已 \n");printf(" | | / / 成 \n");printf(" | | / / 功 \n");printf(" | |/ ;-._ 取 \n");printf(" } ` _/ / ; 編 \n");printf(" | /` ) / / 號 \n");printf(" | / /_/\\_/\\ , \n");printf(" | / / \\ 請 \n");printf(" ( '\\ '- | 耐 \n");printf(" \\ ` . / 心 \n");printf(" | | 等 \n");printf(" | | 候 \n");}break;}case 2:{Bank_Sys_Init();load(*common, COMMON);id = Bank_Sys_Get_Id(COMMON);num = Bank_Get_User_Num(COMMON);write(*common, COMMON);Bank_Sys_Term();if (id == -1)printf("\n編號已經爆棚了,你需要等幾分鐘------the number is too large, you have to wait several minutes !\n\n");else{system("cls");printf("\n\n您的編號為%d -----you get the common %d\n", id, id);printf("現在有 %d 個人在您前面排隊\n\n", num - 1, num - 1);//--------------------------------------------------------------------printf(" .''. .''. 您 \n");printf(" | | / / 已 \n");printf(" | | / / 成 \n");printf(" | | / / 功 \n");printf(" | |/ ;-._ 取 \n");printf(" } ` _/ / ; 編 \n");printf(" | /` ) / / 號 \n");printf(" | / /_/\\_/\\ , \n");printf(" | / / \\ 請 \n");printf(" ( '\\ '- | 耐 \n");printf(" \\ ` . / 心 \n");printf(" | | 等 \n");printf(" | | 候 \n");}break;}case 3:{system("cls");User_dispaly();system("pause");Bank_Sys_Term();remove("VIP.txt");remove("COMMON.txt");return 0;}}system("pause");}}return 0;}
include"queue.h"是自己寫好的頭文件,c++的鏈隊列比較容易實現就不放出來了
?
?
總結
以上是生活随笔為你收集整理的基于链队列的银行叫号系统的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。