【练习】银行排号程序

  随着银行业务的扩展, 到银行办理业务的人越来越多,经常可以见到银行营业大厅中排着长队。为了改善服务,很多银行都设置了排号系统,顾客去办理业务时,通过排号机生成一个好吗,然后可坐在在休息区等候排号系统按号码进行呼叫,而从不需要用户站在柜台前等候,缓解用户等候时的烦躁情绪。本程序为模拟该排号系统的实例。

  • 实现源码
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef struct
{
    int num; //顾客编号
    long time;//进入队列时间
}DATA;
#include "2-12 CycQueue.h"
int num;//顾客序号
void add(CycQueue *q) //新增顾客排列
{
    DATA data;
    if(!CycQueueIsFull(q)) //如果队列未满
    {
        data.num=++num;
        data.time=time(NULL);
        CycQueueIn(q,data);
    }
    else
        printf("\n排队的人太多,请稍候再排队!\n");
}
void next(CycQueue *q) //通知下一顾客准备
{
    DATA *data;
    if(!CycQueueIsEmpty(q)) //若队列不为空
    {
        data=CycQueueOut(q); //取队列头部的数据
        printf("\n请编号为%d的顾客办理业务!\n",data->num);
    }
    if(!CycQueueIsEmpty(q)) //若队列不为空
    {
        data=CycQueuePeek(q);//取队列中指定位置的数据
        printf("请编号为%d的顾客准备,马上将为您理业务!\n",data->num);
    }
}
int main()
{
    CycQueue *queue1;
    int i,n;
    char select;
    num=0;//顾客序号
    queue1=CycQueueInit(); //初始化队列
    if(queue1==NULL)
    {
        printf("创建队列时出错!\n");
        getch();
        return 0;
    }
    do{
        printf("\n请选择具体操作:\n");
        printf("1.新到顾客\n");
        printf("2.下一个顾客\n");
        printf("0.退出\n") ;
        fflush(stdin);
        select=getch();
        switch(select)
        {
            case '1':
                add(queue1);
                printf("\n现在共有%d位顾客在等候!\n",CycQueueLen(queue1));
                break;
            case '2':
                next(queue1);
                printf("\n现在共有%d位顾客在等候!\n",CycQueueLen(queue1));
                break;
            case '0':
                break;
        }
    }while(select!='0');
    CycQueueFree(queue1); //释放队列
    getch();
    return 0;
}
  • 测试结果

    这里写图片描述
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值