"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()
}
#include<stdio.h>int chaxun(int a3)
{
int b
b=a3
printf("你的余额为:%d\n",b)
}
int qukuan(int a3)
{
int a,b
printf("请输入您要提取的现金:\n")
scanf("%d",&a)
b=a3-a
if(b<0)
printf("对不起 ,你的余额不足\n")
else
{
printf("请收好您的%d元现金\n",a)
a3=a3-a
}
return (a3)
}
int gaini(int a2)
{
int a,b,c=1,d,e=1
while(e)
{
printf("请输入你的旧密码:\n")
scanf("%d",&d)
if(d==a2)
e=0
else
{
e=1
printf("你输入的密码错误,请重新输入:\n")
}
}
while(c)
{
printf("请输入您的六位数新密码\n")
scanf("%d",&a2)
printf("请确认您的六位数新密码\n")
scanf("%d",&b)
if(a2==b)
{
if(b>100000&&b<999999&&b/(b/100000)!=111111)
{
c=0
printf("密码修改成功\n")
}
else
{
printf("您输入的密码不符合要求,请从新输入\n")
c=1
}
}
else
{
c=1
printf("您两次输入的密码不一致,请重新输入:\n")
}
}
return a2
}
int quka()
{
printf("\n 梦若保保提醒您\n")
printf("请收好您的卡片,谢谢,再见\n\n")
}
int cunkuan(int a3)
{
int i,j,k
printf("请输入你要存的金额\n")
scanf("%d",&k)
if(k<0)
{
printf("对不起,没有负存款\n")
}
else
{
printf("\n您好,您已经存进去了%d元\n",k)
a3=a3+k
}
return a3
}
main()
{
int i,j,b=1,c,k,l,m,n
int a1=123456,a2=123456,a3=1000
printf("欢迎使用自动柜员机:\n\n")
while(b==1)
{
printf("请输入您的账号:\n")
scanf("%d",&k)
printf("请输入您的密码:\n")
scanf("%d",&l)
if(k==a1&&l==a2)
{
b=0
printf("您的账户余额为:%d\n",a3)
}
else
{
b=1
printf("对不起,您输入的账号或者密码有误,请重新输入:\n")
}
}
do
{
printf("\n请选择您要的服务项目:\n")
printf("1.查询余额\n")
printf("2.取款\n")
printf("3.修改密码\n")
printf("4.取卡\n")
printf("5.存款\n")
scanf("%d",&c)
switch(c)
{
case 1:
chaxun(a3)
break
case 2:
a3=qukuan(a3)
break
case 3:
a2=gaini(a2)
break
case 4:
quka()
break
case 5:
a3=cunkuan(a3)
break
}
}while(c!=4)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)