C语言模拟银行业务系统
1、首先打开VC++6.0

3、选择C++ source file 新建一个空白文档

5、建立4个结构体,分别是客户记录 节点 队列 事件typedef struct{ int ArrivalTime; int Duration;}QElemType;struct LinkNode{ Event data; struct LinkNode *next;};typedef struct LinkNode LNode;typedef struct LinkNode *LinkList;typedef struct LinkNode *EvenList;typedef struct QNode{ QElemType elem; struct QNode *next;}QNode,*QueuePtr;typedef struct LinkQueue{ QueuePtr front; QueuePtr rear;}LinkQueue;

7、链表的相关操作/*初始化有序链表*/int InitList(EvenList *L){ *L=(LNode *)malloc(sizeof(LNode)); if(!(*L)) exit(0); (*L)->next=NULL; return 1;}/*删除链头元素*/int DeHead(EvenList *L,Event *e){ LNode *pc,*q; pc=*L; q=pc->next; pc->next=q->next; *e=q->data;return 1;}/*判断有序链表是否为空*/int ListEmpty(LNode L){ LNode *p; int j=0; p=L.next; while(p) { j++;break; } if(j==0) return 1; else return 0;/*判断两个事件的发生时刻*/int CmpTime(Event a,Event b){ if(a.OccurTime>b.OccurTime) return 1; else if(a.OccurTime==b.OccurTime) return 0; else return -1;}

9、注销链表,节省空间void DestroyList(EvenList *L)/*销毁表*/{ LNode *p; while(*L) { p=(*L)->next; free(*L); *L=p; }}

11、处理事件的函数void CustomerDeparture()/*处理客户什置葆鸳离开事件*/{ int i; i=en.NType; DelQueue(&q[i],&customer);/*删除第i队列的排头客户*/ TotalTime+=en.OccurTime-customer.ArrivalTime;/*累计客户逗留时间*/ if(!QueueEmpty(q[i]))/*设定第i队列的一个将要离开事件并插入事件表*/ { GetHead(q[i],&customer);/*得到它的资料*/ en.OccurTime+=customer.Duration;en.NType=i; OrderInsert(&ev,en,CmpTime); }}void Bank_Simulation(){ OpenForDay();/*初始化*/ while(!ListEmpty(*ev))/*非空时,删掉表里的第一个*/ { DeHead(&ev,&en); if(en.NType==0) CustomerArrived();/*是客户还没办理的,就处理到达事件*/ else CustomerDeparture();/*否则处理离开事件*/ } printf("The Average Time is %.3f\n\n",(float)TotalTime/CustomerNum);}
