银行排队系统
【问题描述】
试设计一个银行排队系统,模拟一般银行的日常对外营业服务,包括顾客到达、等待、办理业务及离开等事件。要求体现“先来先服务”的原则,将传统物理的多个顾客排队队列变为一个逻辑队列处理,顾客只需取票(即刻进队,排队),等待叫号即可。
【基本要求】
设计程序,要求能够实现以下功能:
(1)顾客到达银行时能拿到排队号码,并能知道需要等待的人数。如果是VIP顾客,那么能直接进入VIP窗口办理,无需加入普通顾客的等待;
(2)可以查看每个银行窗口正在给第几号顾客办理业务;
(3)顾客离开银行时,可以对银行窗口职员的服务进行评价。
感谢以下两位大佬,salute!
@小白白^
@电脑迷2013
VS2022版:文章来源:https://www.toymoban.com/news/detail-766384.html
#include<stdio.h>
#include<stdlib.h>
#include <time.h>
#include<conio.h>
static int i = 1;
void date();
void CustomerReview();
typedef struct QNode
{
int bianhao;//队内成员取到的号码
struct QNode* next;
}QNode, * QueuePtr;
typedef struct
{
QueuePtr front;//队头指针
QueuePtr rear;//队尾指针
}Queue;//创建链式队列
void initQueue(Queue* q)//队列的初始化
{
q->front = q->rear = (QNode*)malloc(sizeof(QNode));
if (!q->front)//初始化失败退出
{
return;
}
q->front->next = NULL;
}
Queue s1, s2, s3;//创建三个队列窗口
int shows1()//显示1窗口人员
{
QNode* p = (QNode*)malloc(sizeof(QNode));
if (s1.front == s1.rear)
{//队列为空队列
printf("当前无排队人员 *\n");
return 0;
}
p = s1.front->next;
while (p)
{
printf("%d ", p->bianhao);
p = p->next;
}
printf("\n");
}
int shows2()//显示2窗口人员
{
QNode* p = (QNode*)malloc(sizeof(QNode));
if (s2.front == s2.rear)
{//队列为空队列
printf("当前无排队人员 *\n");
return 0;
}
p = s2.front->next;
while (p)
{
printf("%d ", p->bianhao);
p = p->next;
}
printf("\n");
}
int shows3()//显示3窗口人员
{
QNode* p = (QNode*)malloc(sizeof(QNode));
if (s3.front == s3.rear)
{//队列为空队列
printf("当前无排队人员 *\n");
return 0;
}
p = s3.front->next;
while (p)
{
printf("%d ", p->bianhao);
p = p->next;
}
printf("\n");
}
void show()//总显示窗口
{
printf("\n\t\t\t\t\t*1号窗口排队人员:");
shows1();
printf("\n\t\t\t\t\t*2号窗口排队人员:");
shows2();
printf("\n\t\t\t\t\t*3号窗口排队人员:");
shows3();
printf("\t\t\t\t\t");
system("pause");
}
void EnQueue1(Queue* q, int i)//队列插入
{
QNode* p = (QNode*)malloc(sizeof(QNode));
p->bianhao = i;
p->next = NULL;
q->rear->next = p;
q->rear = p;
}
int DeQueue(Queue* q, int e)//队列删除
{
if (q->front == q->rear)
{//队列为空队列
return 1;
}
QNode* p = (QNode*)malloc(sizeof(QNode));
p = q->front->next;
e = p->bianhao;
q->front->next = p->next;
if (q->rear == p)
{
q->rear = q->front;
}
free(p);
}
void EnQueue()//选择窗口插入
{
show();
printf("\t\t\t\t\t*********************************\n");
printf("\t\t\t\t\t*请选择窗口服务:\t\t*\n");
printf("\t\t\t\t\t*\t 1.1号窗口 *\n");
printf("\t\t\t\t\t*\t 2.2号窗口 *\n");
printf("\t\t\t\t\t*\t 3.3号窗口 *\n");
printf("\t\t\t\t\t*********************************\n");
int a;
printf("\t\t\t\t\t");
scanf_s("%d", &a);
switch (a)
{
case 1:
{
EnQueue1(&s1, i);
printf("\t\t\t\t\t*取号成功,你是1号窗口%d号,请等待办理*\n\t\t\t\t\t", i);
i++;
break;
}
case 2:
{
EnQueue1(&s2, i);
printf("\t\t\t\t\t*取号成功,你是2号窗口%d号,请等待办理*\n\t\t\t\t\t", i);
i++;
break;
}
case 3:
{
EnQueue1(&s3, i);
printf("\t\t\t\t\t*取号成功,你是3号窗口%d号,请等待办理*\n\t\t\t\t\t", i);
i++;
break;
}
default:
{
printf("\t\t\t\t\t* 无效窗口 *\n\t\t\t\t\t\n");
printf("\t\t\t\t\t* ");
break;
}
}
system("pause");
system("cls");
}
void vip1(Queue* q, int i)//vip头插
{
QNode* p = (QNode*)malloc(sizeof(QNode));
if (q->front == q->rear)
{
p->bianhao = i;
p->next = NULL;
q->rear->next = p;
q->rear = p;
}
else
{
p->bianhao = i;
p->next = q->front->next;
q->front->next = p;
}
}
void vip2()//vip插队
{
printf("\t\t\t\t\t*********************************\n");
printf("\t\t\t\t\t*请选择窗口服务:\t\t*\n");
printf("\t\t\t\t\t*\t 1.1号窗口 *\n");
printf("\t\t\t\t\t*\t 2.2号窗口 *\n");
printf("\t\t\t\t\t*\t 3.3号窗口 *\n");
printf("\t\t\t\t\t*********************************\n");
int a;
printf("\t\t\t\t\t");
scanf_s("%d", &a);
switch (a)
{
case 1:
{
vip1(&s1, i);
printf("\t\t\t\t\t*取号成功,你是1号窗口%d号,请等待办理*\n\t\t\t\t\t", i);
i++;
break;
}
case 2:
{
vip1(&s2, i);
printf("\t\t\t\t\t*取号成功,你是2号窗口%d号,请等待办理*\n\t\t\t\t\t", i);
i++;
break;
}
case 3:
{
vip1(&s3, i);
printf("\t\t\t\t\t*取号成功,你是3号窗口%d号,请等待办理*\n\t\t\t\t\t", i);
i++;
break;
}
default:
{
printf("\t\t\t\t\t* 无效窗口 *\n\t\t\t\t\t\n");
printf("\t\t\t\t\t* ");
break;
}
}
system("pause");
system("cls");
}
int CallNum(Queue* q)//查找/叫号功能
{
printf("\t\t\t\t\t* 请输入所取的号码:");
int a;
int b = 1;
scanf_s("%d", &a);
QNode* p = q->front->next;
while (p && p->bianhao != a)
{
p = p->next;
b++;
}
if (p == NULL || p->bianhao != a)
{
printf("\t\t\t\t\t* 对不起,您输入的号码不存在! *\n");
printf("\t\t\t\t\t");
system("pause");
return 1;
}
if (b == 1)
{
printf("\t\t\t\t\t*\t 你现在是第1位! \t*\n");
int e = 0;
DeQueue(q, e);
printf("\t\t\t\t\t*\t 办理完成! \t*\n");
CustomerReview();
}
if (b != 1 && (p != NULL || p->bianhao == a))
{
printf("\t\t\t\t\t* 你现在是第%d位,请等候谢谢! *\n", b);
printf("\t\t\t\t\t");
system("pause");
}
return 1;
}
void CounterServer()//柜员
{
printf("\t\t\t\t\t* 柜员您好,请输入您的服务窗口:*\n");
printf("\t\t\t\t\t*********************************\n");
printf("\t\t\t\t\t*\t 1.1号窗口 *\n");
printf("\t\t\t\t\t*\t 2.2号窗口 *\n");
printf("\t\t\t\t\t*\t 3.3号窗口 *\n");
printf("\t\t\t\t\t*********************************\n");
int a;
printf("\t\t\t\t\t");
scanf_s("%d", &a);
switch (a)
{
case 1:
{
printf("\t\t\t\t\t*\t1号窗口:");
shows1();
CallNum(&s1);
break;
}
case 2:
{
printf("\t\t\t\t\t*\t2号窗口:");
shows2();
CallNum(&s2);
break;
}
case 3:
{
printf("\t\t\t\t\t*\t3号窗口:");
shows3();
CallNum(&s3);
break;
}
default:
{
printf("\t\t\t\t\t*\t 无效柜号 \t\t*\n\t\t\t\t\t\n");
printf("\t\t\t\t\t* ");
system("pause");
system("cls");
break;
}
}
}
void CustomerReview()
{
printf("\n\t\t\t\t\t*********************************\n");
printf("\t\t\t\t\t*\t请对本次服务做出评价\t*\n");
printf("\t\t\t\t\t*\t1.非常满意!\t\t*\n");
printf("\t\t\t\t\t*\t2.比较满意!\t\t*\n");
printf("\t\t\t\t\t*\t3.一般!\t\t*\n");
printf("\t\t\t\t\t*\t4.不满意!\t\t*\n");
printf("\t\t\t\t\t*********************************\n");
int a;
printf("\t\t\t\t\t");
scanf_s("%d", &a);
while (a < 1 || a > 4)
{
printf("\t\t\t\t\t* 您的输入不正确,请重新输入: ");
scanf_s("%d", &a);
}
switch (a)
{
case 1:
case 2:
case 3:
case 4:
{
printf("\t\t\t\t\t* 非常感谢你的评价!谢谢! *\n");
printf("\t\t\t\t\t*\t");
system("pause");
system("cls");
break;
}
default:break;
}
}
void esc()
{
exit(0);
}
void menu()
{
date();
printf("\n\n\n\n\n\n\n\n\n");
printf("\t\t\t\t\t*********************************\n");
printf("\t\t\t\t\t***********银行排队系统**********\n");
printf("\t\t\t\t\t*********************************\n");
printf("\t\t\t\t\t*\t请选择服务:\t\t*\n");
printf("\t\t\t\t\t*\t1.普通用户排队\t\t*\n");
printf("\t\t\t\t\t*\t2.vip用户通道\t\t*\n");
printf("\t\t\t\t\t*\t3.显示各窗口等待人数\t*\n");
printf("\t\t\t\t\t*\t4.柜员服务界面\t\t*\n");
printf("\t\t\t\t\t*\t0.退出系统\t\t*\n");
printf("\t\t\t\t\t*********************************\n");
int a;
printf("\t\t\t\t\t");
scanf_s("%d", &a);
switch (a)
{
case 1:
{
system("cls");
date();
printf("\t\t\t\t\t*\t1.普通用户排队\t\t*\n");
EnQueue();
break;
}
case 2:
{
system("cls");
date();
printf("\t\t\t\t\t*\t2.vip用户通道\t\t*\n");
vip2();
break;
}
case 3:
{
system("cls");
date();
printf("\t\t\t\t\t*\t3.显示各窗口等待人数\t*\n");
show();
system("cls");
break;
}
case 4:
{
system("cls");
date();
printf("\t\t\t\t\t*\t4.柜员服务界面\t\t*\n");
CounterServer();
system("cls");
break;
}
case 0:
{
esc();
break;
}
default:
{
printf("\t\t\t\t\t*\t 服务项输入有误 \t*\n");
printf("\t\t\t\t\t*\t");
system("pause");
system("cls");
break;
}
}
}
void date()
{
time_t rawtime;
struct tm timeinfo;
char buffer[128];
time(&rawtime);
localtime_s(&timeinfo, &rawtime);
strftime(buffer, sizeof(buffer), "%Y/%m/%d %H:%M:%S", &timeinfo);
puts(buffer);
}
int main()//
{
system("color 0b");
static int i = 1;
initQueue(&s1);
initQueue(&s2);
initQueue(&s3);
while (1)
{
menu();
}
}
DevCpp版:文章来源地址https://www.toymoban.com/news/detail-766384.html
#include<stdio.h>
#include<stdlib.h>
#include <time.h>
#include<conio.h>
static int i=1;
//void menu();
void date ();
void CustomerReview();
typedef struct QNode
{ int bianhao;//队内成员取到的号码
struct QNode *next;
}QNode,* QueuePtr;
typedef struct
{ QueuePtr front;//队头指针
QueuePtr rear;//队尾指针
}Queue;//创建链式队列
void initQueue(Queue *q)//队列的初始化
{
q->front=q->rear=(QNode *)malloc(sizeof(QNode));
if (!q->front)//初始化失败退出
{
return;
}
q->front->next=NULL;
}
Queue s1,s2,s3;//创建三个队列窗口
int shows1()//显示1窗口人员
{
QNode *p = (QNode *)malloc(sizeof(QNode));
if(s1.front==s1.rear)
{//队列为空队列
printf("当前无排队人员 *\n");
return 0;
}
p=s1.front->next;
while(p)
{
printf("%d ",p->bianhao);
p=p->next;
}
printf("\n");
}
int shows2()//显示2窗口人员
{
QNode *p = (QNode *)malloc(sizeof(QNode));
if(s2.front==s2.rear)
{//队列为空队列
printf("当前无排队人员 *\n");
return 0;
}
p=s2.front->next;
while(p)
{
printf("%d\t",p->bianhao);
p=p->next;
}
printf("\n");
}
int shows3()//显示3窗口人员
{
QNode *p = (QNode *)malloc(sizeof(QNode));
if(s3.front==s3.rear){//队列为空队列
printf("当前无排队人员 *\n");
return 0;
}
p=s3.front->next;
while(p)
{
printf("%d\t",p->bianhao);
p=p->next;
}
printf("\n");
}
void show()//总显示窗口
{
printf("\n\t\t\t\t\t*1号窗口排队人员:");
shows1();
printf("\n\t\t\t\t\t*2号窗口排队人员:");
shows2();
printf("\n\t\t\t\t\t*3号窗口排队人员:");
shows3();
printf("\t\t\t\t\t");
system("pause");
}
void EnQueue(Queue &q,int &i)//队列插入
{
QNode *p = (QNode *)malloc(sizeof(QNode));
p->bianhao=i;
p->next=NULL;
q.rear->next=p;
q.rear=p;
}
int DeQueue(Queue &q,int &e)//队列删除
{
if(q.front==q.rear)
{//队列为空队列
return 1;
}
QNode *p = (QNode *)malloc(sizeof(QNode));
p=q.front->next;
e=p->bianhao;
q.front->next=p->next;
if(q.rear==p)
{
q.rear=q.front;
}
free(p);
}
void EnQueue()//选择窗口插入
{
show();
printf("\t\t\t\t\t*********************************\n");
printf("\t\t\t\t\t*请选择窗口服务:\t\t*\n");
printf("\t\t\t\t\t*\t 1.1号窗口 *\n");
printf("\t\t\t\t\t*\t 2.2号窗口 *\n");
printf("\t\t\t\t\t*\t 3.3号窗口 *\n");
printf("\t\t\t\t\t*********************************\n");
int a;
printf("\t\t\t\t\t");
scanf("%d",&a);
switch(a)
{
case 1:
{
EnQueue(s1,i);
printf("\t\t\t\t\t*取号成功,你是1号窗口%d号,请等待办理*\n\t\t\t\t\t",i);
i++;
break;
}
case 2:
{
EnQueue(s2,i);
printf("\t\t\t\t\t*取号成功,你是2号窗口%d号,请等待办理*\n\t\t\t\t\t",i);
i++;
break;
}
case 3:
{
EnQueue(s3,i);
printf("\t\t\t\t\t*取号成功,你是3号窗口%d号,请等待办理*\n\t\t\t\t\t",i);
i++;
break;
}
default:
{
printf("\t\t\t\t\t* 无效窗口 *\n\t\t\t\t\t\n");
printf("\t\t\t\t\t* ");
break;
}
}
system("pause");
system("cls");
}
void vip1(Queue &q,int &i)//vip头插
{
QNode *p = (QNode *)malloc(sizeof(QNode));
if(q.front==q.rear)
{
p->bianhao=i;
p->next=NULL;
q.rear->next=p;
q.rear=p;
}
else
{
p->bianhao=i;
p->next=q.front->next;
q.front->next=p;
}
}
void vip2()//vip插队
{
printf("\t\t\t\t\t*********************************\n");
printf("\t\t\t\t\t*请选择窗口服务:\t\t*\n");
printf("\t\t\t\t\t*\t 1.1号窗口 *\n");
printf("\t\t\t\t\t*\t 2.2号窗口 *\n");
printf("\t\t\t\t\t*\t 3.3号窗口 *\n");
printf("\t\t\t\t\t*********************************\n");
int a;
printf("\t\t\t\t\t");
scanf("%d",&a);
switch(a)
{
case 1:
{
vip1(s1,i);
printf("\t\t\t\t\t*取号成功,你是1号窗口%d号,请等待办理*\n\t\t\t\t\t",i);
i++;
break;
}
case 2:
{
vip1(s2,i);
printf("\t\t\t\t\t*取号成功,你是2号窗口%d号,请等待办理*\n\t\t\t\t\t",i);
i++;
break;
}
case 3:
{
vip1(s3,i);
printf("\t\t\t\t\t*取号成功,你是3号窗口%d号,请等待办理*\n\t\t\t\t\t",i);
i++;
break;
}
default:
{
printf("\t\t\t\t\t* 无效窗口 *\n\t\t\t\t\t\n");
printf("\t\t\t\t\t* ");
break;
}
}
system("pause");
system("cls");
}
int CallNum(Queue &q)//查找/叫号功能
{
printf("\t\t\t\t\t* 请输入所取的号码:");
int a;
int b = 1;
scanf("%d", &a);
QNode *p = q.front->next;
while (p && p->bianhao != a)
{
p = p->next;
b++;
}
if (p == NULL || p->bianhao != a)
{
printf("\t\t\t\t\t* 对不起,您输入的号码不存在! *\n");
printf("\t\t\t\t\t");
system("pause");
return 1;
}
if (b == 1)
{
printf("\t\t\t\t\t*\t 你现在是第1位! \t*\n");
int e = 0;
DeQueue(q, e);
printf("\t\t\t\t\t*\t 办理完成! \t*\n");
CustomerReview();
}
if (b != 1&&(p != NULL || p->bianhao == a))
{
printf("\t\t\t\t\t* 你现在是第%d位,请等候谢谢! *\n", b);
printf("\t\t\t\t\t");
system("pause");
}
return 1;
}
void CounterServer()//查询排队进度
{
printf("\t\t\t\t\t* 柜员您好,请输入您的服务窗口:*\n");
printf("\t\t\t\t\t*********************************\n");
printf("\t\t\t\t\t*\t 1.1号窗口 *\n");
printf("\t\t\t\t\t*\t 2.2号窗口 *\n");
printf("\t\t\t\t\t*\t 3.3号窗口 *\n");
printf("\t\t\t\t\t*********************************\n");
int a;
printf("\t\t\t\t\t");
scanf("%d",&a);
switch(a)
{
case 1:
{
printf("\t\t\t\t\t*\t1号窗口:");
shows1();
CallNum(s1);
break;
}
case 2:
{
printf("\t\t\t\t\t*\t2号窗口:");
shows2();
CallNum(s2);
break;
}
case 3:
{
printf("\t\t\t\t\t*\t3号窗口:");
shows3();
CallNum(s3);
break;
}
default:
{
printf("\t\t\t\t\t*\t 无效窗口 \t\t*\n\t\t\t\t\t\n");
printf("\t\t\t\t\t* ");
system("pause");
system("cls");
break;
}
}
}
void CustomerReview()
{
printf("\n\t\t\t\t\t*********************************\n");
printf("\t\t\t\t\t*\t请对本次服务做出评价\t*\n");
printf("\t\t\t\t\t*\t1.非常满意!\t\t*\n");
printf("\t\t\t\t\t*\t2.比较满意!\t\t*\n");
printf("\t\t\t\t\t*\t3.一般!\t\t*\n");
printf("\t\t\t\t\t*\t4.不满意!\t\t*\n");
printf("\t\t\t\t\t*********************************\n");
int a;
printf("\t\t\t\t\t");
scanf("%d",&a);
while (a < 1 || a > 4)
{
printf("\t\t\t\t\t* 您的输入不正确,请重新输入: ");
scanf("%d", &a);
}
switch(a)
{
case 1:
case 2:
case 3:
case 4:
{
printf("\t\t\t\t\t* 非常感谢你的评价!谢谢! *\n");
printf("\t\t\t\t\t*\t");
system("pause");
system("cls");
break;
}
default:break;
}
}
void exit()
{
exit(0);
}
void menu()
{
date ();
printf("\n\n\n\n\n\n\n\n\n");
printf("\t\t\t\t\t*********************************\n");
printf("\t\t\t\t\t***********银行排队系统**********\n");
printf("\t\t\t\t\t*********************************\n");
printf("\t\t\t\t\t*\t请选择服务:\t\t*\n");
printf("\t\t\t\t\t*\t1.普通用户排队\t\t*\n");
printf("\t\t\t\t\t*\t2.vip用户通道\t\t*\n");
printf("\t\t\t\t\t*\t3.显示各窗口等待人数\t*\n");
printf("\t\t\t\t\t*\t4.柜员服务界面\t\t*\n");
printf("\t\t\t\t\t*\t0.退出系统\t\t*\n");
printf("\t\t\t\t\t*********************************\n");
int a;
printf("\t\t\t\t\t");
scanf("%d",&a);
switch(a)
{
case 1:
{
system("cls");
date ();
printf("\t\t\t\t\t*\t1.普通用户排队\t\t*\n");
EnQueue();
break;
}
case 2:
{
system("cls");
date ();
printf("\t\t\t\t\t*\t2.vip用户通道\t\t*\n");
vip2();
break;
}
case 3:
{
system("cls");
date ();
printf("\t\t\t\t\t*\t3.显示各窗口等待人数\t*\n");
show();
system("cls");
break;
}
case 4:
{
system("cls");
date ();
printf("\t\t\t\t\t*\t4.柜员服务界面\t\t*\n");
CounterServer();
system("cls");
break;
}
case 0:
{
exit();
break;
}
default:
{
printf("\t\t\t\t\t*\t 服务项输入有误 \t*\n");
printf("\t\t\t\t\t*\t");
system("pause");
system("cls");
break;
}
}
}
void date()
{
time_t rawtime;
struct tm * timeinfo;
char buffer [128];
time (&rawtime);
timeinfo = localtime (&rawtime);
strftime (buffer,sizeof(buffer),"%Y/%m/%d %H:%M:%S",timeinfo);
puts (buffer);
}
int main()//
{
system("color 0b") ;
static int i=1;
initQueue(&s1);
initQueue(&s2);
initQueue(&s3);
while(1)
{
menu();
}
}
到了这里,关于【NJUPT】 数据结构与算法分析_银行排队系统的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!