| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 773 人关注过本帖
标题:[求助]谁能修改“银行业务模拟”代码
只看楼主 加入收藏
lj落叶
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-6-3
收藏
 问题点数:0 回复次数:0 
[求助]谁能修改“银行业务模拟”代码

客户业务分2种,第一种是申请从银行得到一笔资金,即借款或取款。第2种是向银行投入一笔资金,即存款或还款。银行有2个服务窗口,相应地有2个队列。客户到达银行后先排第一个队。处理每个客户业务时,如果属于第一种,且申请额超出银行现存资金总额尔得不到要求,则立刻排入第2个队等候,直至满足时才离开银行,否则业务处理完后立刻离开银行。没接待完一个第二种业务的客户,则顺序检查和处理(如果可能)第二个队列中的得客户,对能满足的申请者予以满足,不能满足者重新排到第二个队列的队尾。注意,再此检查过程中,一旦银行资金总额少于或等于刚才第一个队列中最后一个客户(第2中业务)被接待之前的数额,或者本次以将第2个队列检查或者处理了一遍,就停止检查(因为此时已不可能还有满足者)转而继续接待第一个队列的客户。任何时刻都只能开一个窗口。假设检查不需要时间。营业时间结束时所有客户立即离开银行。

写一个上述银行业务的事件驱动模拟系统,通过模拟方法求出客户在银行内逗留的平均时间。

基本要求: 利用动态存储结构实现模拟,即利用c语言的动态分配函数malloc和free.

测试数据:
一天营业开始时银行拥有的款额为10000¥营业时间为600分钟。其他模拟参数自定,注意测定2种极端的情况:1是2个到达事件之间的间隔时间很短,而客户的交易时间很长,另一个恰好相反,设置2个到达事件的间隔时间很长。而客户的交易时间很短。

实现提示:

事件有2类:到达银行和离开银行。初识时银行现存资金总额为total。开始营业后的第一个事件是客户到达,营业时间从0到ciosetime.到达事件发生时随机地设置次客户的交易时间和距下个到达事件的时间间隔。每个客户要办理的款额也是随机确定的,用负值和正值分别表示第一类和第2类业务。变量toeal. ciosetime以及上述2个随即量的上下界均交互地从终端读入,作为模拟参数。

#include "iostream.h"
#include "stdlib.h"
#include "time.h"
#define Counter 2
#define null 0
#define CloseTime 480 //全天银行的工作时间//
int TotalTime,CustomerNum;
struct Event
{
int Occurtime;
int NType;
Event *next;
};
struct QueueElem
{
int Arrival;
int duration;
QueueElem *next;
};
struct QueueList
{
QueueElem *front;
QueueElem *rear;
int Count;
};
typedef Event* EventList;
typedef QueueList* QuListArray;
void InitQuList(QueueList &Queue)
{
Queue.front=new QueueElem;
Queue.rear=Queue.front;
Queue.front->Arrival=0;
Queue.front->duration=0;
Queue.front->next=null;
Queue.Count=0;
}
void GetHead(QueueList &Queue,QueueElem &en)
{
en=*Queue.front->next;
en.next=null;
}
void EnQueue(QueueList &Queue,QueueElem &en)
{
QueueElem *P=new QueueElem;
*P=en;
Queue.rear->next=P;
Queue.rear=P;
Queue.Count++;
}
void DeQueue(QueueList &Queue,int &e)
{
if(Queue.front!=Queue.rear)
{
QueueElem *P=Queue.front->next;
Queue.front->next=P->next;
if(Queue.rear==P)
{
Queue.rear=Queue.front;
}
e=P->Arrival;
delete P;
Queue.Count--;
}
}
void InitEVList(EventList &EV)
{
EV=new Event;
EV->NType=0;
EV->Occurtime=0;
EV->next=null;
}
int cmp(Event a,Event b)
{
if(a.Occurtime>b.Occurtime)
{
return 1;
}
else if(a.Occurtime<b.Occurtime)
{
return -1;
}
else
{
return 0;
}
}
void InsertEvent(EventList &EV,Event &en,int(*cmp)(Event,Event))
{
Event *P,*Q;
Event *Temp=new Event;
*Temp=en;
P=Q=EV;
P=P->next;
if(P!=null)
{
while(P!=null)
{
if(cmp(*P,en)==-1)
{
P=P->next;
Q=Q->next;
}
else if(cmp(*P,en)==1)
{
Temp->next=P;
Q->next=Temp;
return;
}
else
{
P->next=Temp;
return;
}
}
Q->next=Temp;
Temp->next=P;
}
else
{
Q->next=Temp;
Temp->next=null;
}
}
void OpenForDay(EventList &EV,QuListArray &QuPoint)
{
Event *temp;
temp=new Event;
TotalTime=0;
CustomerNum=0;
temp->NType=0;
temp->Occurtime=0;
EV->next=temp;
temp->next=null;

}
int Minimum(QuListArray &QuPoint)
{
int i=0,j=0,Min=QuPoint[0].Count;
for(i;i<Counter;i++)
{
if(Min>QuPoint[i].Count)
{
Min=QuPoint[i].Count;
j=i;
}
}
return j;
}
void CustomerArrived(EventList &EV,Event &en,QuListArray &QuPoint)
{

int i,j,t,Min;
srand(time(NULL));
i=1+rand()%30;//客户办理业务所要时间,不大于30分钟//
j=1+rand()%5; //下个客户到达的时间间隔,不大于5分钟//
t=en.Occurtime+j;//下个客户到达时间//
Event Temp={t,0,null};
if(t<CloseTime)
{
CustomerNum++;
InsertEvent(EV,Temp,cmp);
}
Min=Minimum(QuPoint);
QueueElem temp={en.Occurtime,i,null};

EnQueue(QuPoint[Min],temp);
if(QuPoint[Min].Count==1)
{
Event Temp={en.Occurtime+i,Min+1,null};
InsertEvent(EV,Temp,cmp);
}
}
int EmptyQueue(QueueList &Queue)
{
if(Queue.Count==0)
{
return 1;
}
else
{
return 0;
}
}
void CustomerDepartment(EventList &EV,Event &en,QuListArray &QuPoint)
{
int i=en.NType,arrival;
DeQueue(QuPoint[i-1],arrival);
TotalTime=TotalTime+en.Occurtime-arrival;
if(!EmptyQueue(QuPoint[i-1]))
{
QueueElem En;
GetHead(QuPoint[i-1],En);
Event temp={En.duration+en.Occurtime,i,null};
InsertEvent(EV,temp,cmp);
}
}
int EmptyEV(EventList &EV)
{
if(EV->next==null)
{
return 1;
}
else
{
return 0;
}
}
void DeFirstEV(EventList &EV,Event &en)
{
Event *temp;
temp=EV->next;
EV->next=temp->next;
en=*temp;
delete temp;
}

void main()
{

Event en;
EventList EV;
InitEVList(EV);
QueueList Q[Counter];
QuListArray QuPoint;
QuPoint=Q;
for(int i=0;i<Counter;i++)
{
InitQuList(QuPoint[i]);
}

OpenForDay(EV,QuPoint);

while(!EmptyEV(EV))
{
DeFirstEV(EV,en);
if(en.NType==0)
{
CustomerArrived(EV,en,QuPoint);
}
else
{
CustomerDepartment(EV,en,QuPoint);
}
}

cout<<TotalTime/CustomerNum<<endl;

帮我检查一下哪里出错了

搜索更多相关主题的帖子: 银行业务模拟 客户 队列 代码 资金 
2007-06-03 11:44
快速回复:[求助]谁能修改“银行业务模拟”代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011831 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved