设计银行模拟业务系统

1.问题描述
(1)假设某银行有四个窗口对外接待客户,从早晨银行开门起不断有客户进入银行。由于每个窗口在某个时刻只能接待一个客户,因此在客户人数众多时需在每个窗口前顺次排队,对于刚进入银行的客户,如果某个窗口的业务员正空闲,则可上前办理业务,反之,若四个窗口均有客户所占,他便会排在人数最少的队伍后面。现在需要编制程序以模拟银行的这种业务活动并计算一天中客户在银行逗留的平均时间。
(2)初始化(OpenForDay),模拟银行开门时各数据结构的状态。
(3)事件驱动(EventDrived), 对客户到达和离开事件做相应处理。
(4)下班处理(CloseForDay),模拟银行关门时的动作,统计客户平均逗留时间。
2.问题分析
(1)银行系统运转涉及到的对象有窗口和客户。窗口反映的是排队的客户,所以应该采用队的数据结构。入队出队的操作符合现实生活中银行排队的模式,每个客户的信息应该存入代表窗口的队中。
(2)客户这个对象含有的属性应该有对应的编号、进入银行和离开银行的时间、所在的窗口号。
(3)题中要求了三个函数,初始化函数可以对窗口队列进行初始化操作,事件驱动函数要完成数据的输入、判断、存储,下班处理为计算平均时间。
3.完整源代码

#include<iostream>
#include<cstring>
#define maxsize 20
using namespace std;

typedef struct{ 
 int hour;
 int minute;
 int name;
}customer;

int delta_T(int hour2,int minute2,int hour1,int minute1)
{
 return (hour2-hour1)*60+(minute2-minute1);
}

typedef struct QNode{
 customer data;
 struct QNode *next;
}QNode,*QueuePtr;
typedef struct
{
 QueuePtr front;
 QueuePtr rear;
 int length;
}LinkQueue;

int OpenForDay(LinkQueue &one,LinkQueue &two,LinkQueue &three,LinkQueue &four)
{
 one.front = one.rear = new QNode;
 two.front = two.rear = new QNode;
 three.front = three.rear = new QNode;
 four.front = four.rear = new QNode;
 one.front->next = two.front->next = three.front->next = four.front->next = NULL;
 one.length=two.length=three.length=four.length=0;
 return 1;
}

int EnQueue(LinkQueue &Q,customer e) //入队 
{
 QNode *p;
 p = new QNode;
 p->data = e;
 p->next = NULL;
 Q.rear->next = p;
 Q.rear = p;
 Q.length++;
 return 1; 
}

int DeQueue(LinkQueue &Q,customer &e)  //出队 
{
 if(Q.front == Q.rear)
  return 0;
 QNode *p;
 p = new QNode;
 p = Q.front->next;
 e = p->data;
 Q.front->next = p->next;
 if(Q.rear == p)
 Q.rear = Q.front;
 delete p;
 Q.length--;
 return 1;
}

customer GetHead(LinkQueue &Q)
{
 if(Q.front != Q.rear)
  return Q.front->next->data;
}

int Select(int a,int b,int c,int d)
{
 if(a== b == c == d)
  return 0;
 if(a>=b && a>=c && a>=d)
  return 1;
 if(b>=a && b>=c && b>=d)
  return 2;
 if(c>=a && c>=b && c>=d)
  return 3;
 if(d>=a && d>=b && d>=c)
  return 4;
}

void EventDrived(LinkQueue &one,LinkQueue &two,LinkQueue &three,LinkQueue &four)
{
 int n,hour,minute,i=0,Time[20],j=0,m=0,total = 0;
 float average;
 for(j=0; j<20; j++){
  Time[j]=0;
 }
 OpenForDay(one,two,three,four);
 while(1)
 {
  customer e;
  int name;
  cout<<"功能选择:1.客户进入   2.客户离开   3.关门"<<endl;
  cin>>n;
  switch(n){
   case 1:
    cout<<"输入客户姓名:";
    cin>>e.name;
    cout<<"进入时间:";
    cin>>e.hour>>e.minute;
    if(one.front == one.rear||two.front == two.rear||three.front == three.rear||four.front == four.rear)
    {
     if(one.front==one.rear)
      EnQueue(one,e);
     else if(two.front == two.rear)
      EnQueue(two,e);
     else if(three.front == three.rear)
      EnQueue(three,e);
     else 
      EnQueue(four,e);  
    }
    else{
     switch(Select(one.length,two.length,three.length,four.length)){
     case 0:EnQueue(one,e);break;
     case 1:EnQueue(one,e);break;
     case 2:EnQueue(two,e);break;
     case 3:EnQueue(three,e);break;
     case 4:EnQueue(four,e);break;
    }
    }
   break;
   case 2:
    cout<<"输入客户编号:";
    cin>>name;
    cout<<"输入离开时间:";
    cin>>hour>>minute;
    if(name==GetHead(one).name)
    {
     DeQueue(one,e);
     Time[i] = delta_T(hour,minute,e.hour,e.minute);
     i++;
     m++;//用户数目 
    }
    else if(name==GetHead(two).name)
    {
     DeQueue(two,e);
     Time[i] = delta_T(hour,minute,e.hour,e.minute);
     i++;
     m++;
    }
    else if(name==GetHead(three).name)
    {
     DeQueue(three,e);
     Time[i] = delta_T(hour,minute,e.hour,e.minute);
     i++;
     m++;
    }
    else
    {
     DeQueue(four,e);
     Time[i] = delta_T(hour,minute,e.hour,e.minute);
     i++;
     m++; 
    }
   break;
   default:break;
   }
 if(n==3){
  for(j=0; j<m; j++)
   total = Time[j] +total;
  average = total/float(m);
  cout<<"客户平均逗留时间:"<<average<<"分钟"<<endl; 
  break;
  }
 }
}

int main()
{
 LinkQueue one,two,three,four;
 OpenForDay(one,two,three,four);
 EventDrived(one,two,three,four);
 return 0;
} 

我一朋友亲戚在银行工作,说平时上班就改些if、else啥的,我还真写了好多if、else【笑哭】【笑哭】
不足之处还望大家指正包含!!

假设银行有n个窗口对外接待客户,从早晨银行9点开门起到5点关门,不断有客户进入银行,由于每个窗口在某个时刻只能接待一个客户。因此在客户人数众多时需要在每个窗口前顺次排队,对于刚进银行客户。如果某个窗口的业务员正空闲,则可上前输业务。反之,若个窗口均有客户所占,他便会排在为数最少的队伍后面。编制一个程序模拟银行的这种业务活动并计算一天中客户银行的平均逗留时间。 首先从题目分析:N个窗口排队,首先就要建立N个队列来存储排队的用户信息 ,然后算出那个队列最短就用户就到那个队伍排队,同时通过随机生成他办理业务的时间和到来的时间,通过计算用户的到来时间和离开时间就可以计算出某个用户在银行的逗留时间 ;话不多说直接上代码。 下面是主函数,由用户输入银行上下班时间,计算营业多长时间Total_time,如何当前时间小于关门的时间,就一直进入customer_into();函数,用户不断的进来 #define FALSE 0 #define TRUE 1 #define QUEUE_SUM 4 //窗口的数量 int rand_business_time=0, rand_wait_time=0;//定义办理时间,等待时间变量 int Total_time=0,now_tim=0;//总时间,当前时间 int go_time[4] = {0,0,0,0};//定义数组存储每个窗口最后一位办理完业务的时间 int sum_nan[4] = {0,0,0,0};//定义数组存储每个窗口排队的人数 int Sign=TRUE; //是否关门标志位 float Sum_Wait_Time=0.0; //等待的总时间 float Sun_Nan=0.0; //总人数 int open_time;//开门时间 int off_time; //关门时间 int main() { Prompted(); printf("输入银行的24小时制营业时间:如营业时间为9:00--17:00,则应输入:9,17\n"); scanf("%d,%d", &open;_time,&off;_time); Total_time = (off_time - open_time) * 60;//计算银行总营业多少分钟 for (int i = 0; i now_time) { customer_into(); //客户进入函数 } printf("银行关门时间到不再接收客人\n\n"); for (int i = 0; i < QUEUE_SUM; i++) { DisposeQueue(&queue;[i],i);//输入在银行关门前还没有办理完业务的客户信息 } printf("平均时间为%.2f分钟",Sum_Wait_Time/Sun_Nan); /*通过各个客户的总等待时间总和/总人数算出逗留平均时间*/ _getch(); return 0; }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值