当前位置:编程学习 > C/C++ >>

用C语言模拟ATM机工作流程编程

一定要C语言啊!VC条件下的!急需急需急需!
答案:#include "stdio.h"对ATM机器的模拟就是一个对队列的模拟下面代码在VC6环境下调试已经通过了其中有个缺陷就是因为代码执行速度过快导致二次执行根据时间随机出来的数字都是一样的因此你可以自己加上一个延迟子程序部分功能已经注释了#include "stdlib.h"#include "time.h"#define  OK 1#define  ERROR 0
typedef struct node{int number;struct node* next;}*Lnode;
typedef struct list{ node *head,*rear;}*Plist;
//模拟 ATM开业bool ListInit(Plist list){ Lnode p;p = (Lnode)malloc(sizeof(Lnode));list->head = p;list->rear = list->head;list->head->next = NULL;if(list->head!=NULL) return ERROR;else return OK;}
//模拟 有客户排队bool ListInsert(Plist list,int number){ Lnode p; p = (Lnode)malloc(sizeof(Lnode)); if(p==NULL) return ERROR; else { p->number = number; p->next = NULL; list->rear->next = p; list->rear = p; return OK;}}
//模拟 客户办完事离开bool ListDelete(Plist list){ Lnode p; if(list->head ==list->rear) return ERROR; else { p = list->head->next; list->head->next = p->next; list->rear = list->head; // free(p); return OK; }}
void sand(int* gettime,int* needtime){srand(time(NULL)) ; *gettime = rand()%100;srand(time(NULL)) ; *needtime =rand()%100;}
//模拟客户到达事件void CustomerArrived(Plist list,int gettime,int needtime,int kehu,int time){ int nextgettime,nextneedtime; sand(&nextgettime,&nextneedtime); while(needtime>0 && nextgettime>0 && time>0){needtime --;nextgettime --;time --;}if(nextgettime == 0 && needtime>0 &&time>0) {kehu++;ListInsert(list,kehu);while(needtime>0 && time>0) {needtime--;time --;} ListDelete(list);CustomerArrived(list,nextgettime,nextneedtime,kehu,time);}if(needtime ==0 && nextgettime>0 && time>0){ ListDelete(list);while(nextgettime>0 && time>0){nextgettime--;time --;} kehu++;ListInsert(list,kehu); //未删除 ,list未传递进去CustomerArrived(list,nextgettime,nextneedtime,kehu,time);}if(time ==0){printf("ATM关门,请明天在来!\n");return;}}
main(){ list list;int i = 10000; //ATM机器每天工作时间int kehu = 0; //客户标号int gettime,needtime;ListInit(&list); //ATM开业sand(&gettime,&needtime); ListInsert(&list,kehu); CustomerArrived(&list,gettime,needtime,kehu,i); getchar();
}


作业要自己写~~ 不要想着上网找啊~~。。。

上一个:关于找相同字符串的C语言函数……
下一个:C语言是么司。?

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,