void main()
{
char SelectKey,CreditMoney,DebitMoney
while(1)
{
do{
clrscr()
puts("Please select key:")
puts("1.Quary")
puts("2.Credit")
puts("3.Debit")
puts("4.Return")
SelectKey=getch()
}while(SelectKey!='1'&&SelectKey!='2'&&SelectKey!='3'&&SelectKey!='4')
switch(SelectKey)
{
case'1':
clrscr()
puts("Your balance is $1000")
getch()
break
case'2':
do{
clrscr()
puts("Please select Credit money:")
puts("1.$50")
puts("2.$100")
puts("3.Return")
CreditMoney=getch()
}while(CreditMoney!='1'&&CreditMoney!='2'&&CreditMoney!='3')
switch(CreditMoney)
{
case'1':
clrscr()
puts("Your Credit money is $50,Thank you!")
getch()
break
case'2':
clrscr()
puts("Your Credit money is $100,Thank you!")
getch()
break
case'3':
break
}
break
case'3':
do{
clrscr()
puts("Please select Debit money:")
puts("1.$50")
puts("2.$100")
puts("3.$500")
puts("4.$1000")
puts("5.Return")
DebitMoney=getch()
}while(DebitMoney!='1'&&DebitMoney!='2'&&DebitMoney!='3'&&DebitMoney!='4'&&DebitMoney!='5')
switch(DebitMoney)
{
case'1':
clrscr()
puts("Your Debit money is $50,Thank you!")
getch()
break
case'2':
clrscr()
puts("Your Debit money is $100,Thank you!")
getch()
break
case'3':
clrscr()
puts("Your Debit money is $500,Thank you!")
getch()
break
case'4':
clrscr()
puts("Your Debit money is $1000,Thank you!")
getch()
break
case'5':
break
}
break
case'4':
return
}
}
}
几个小错误而已...比如忘了写双撇号,switch写错了...还有!= 忘了写! 等等.. 以上程序可以运行了
#include<stdio.h>#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<conio.h>
void
sys(const
char
*ex)
{
printf(ex)
fflush(stdin)
getch()
}
struct
atm
{
float
money
char
card[20]
char
pass[20]
}
struct
atm
*creat()
{
struct
atm
*p
p=(struct
atm
*)malloc(sizeof(struct
atm))
printf("请输入密码:")
gets(p->pass)getchar()
printf("请输入卡号:")
gets(p->card)getchar()
printf("卡号为=%s,密码为=%s\n",p->card,p->pass)
printf("请输入预存款金额:")
scanf("%f",&p->money)
return
p
}
struct
atm
*qukuan(struct
atm
*p)
{
float
money
printf("请输入取款金额:")
scanf("%f",&money)
if(money>p->money){printf("余额不足!\n")return
p}
p->money-=money
return
p
}
void
print(struct
atm
*p)
{
printf("当前余额为%.2f,可取款金额为%d\n",p->money,floor(p->money)/100)
}
int
yanzheng(struct
atm
*p)
{
char
pass[20]
printf("你好,请输入密码:")
gets(pass)
if(strcmp(pass,p->pass)==0)
return
1
return
0
}
void
main()
{
struct
atm
*p
int
t=0
p=creat()
do
t++
while(!yanzheng(p)&&t<3)
if(t==3){printf("密码连续三次输入错误,退出程序!\n")return
1}
while(1)
{
system("cls")
printf("****欢迎您使用ATM取款机!****\n")
printf("1:\t取款\n")
printf("2:\t查看余额\n")
printf("0:\t退出\n")
printf("请选择:")
scanf("%d",&t)
fflush(stdin)
switch(t)
{
case
1:qukuan(p)break
case
2:print(p)break
}
if(!t)
{
sys("请按任意键退出...")
break
}
sys("请按任意键返回...")
}
}
#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()
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)