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

用C语言模拟ATM机工作流程编程,第1张

#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()

}

#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)

}

按照你的愿意把空都填好了,VC++ 6.0下编译能通过,有警告信息,运行基本上能用,不过个人认为这个系统有很大的不足,比如输入账号的时候没有输出反馈信息,以及没有对误 *** 作的处理等等。需要的话可以帮你改改!

#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

#include <string.h>

#define AN 9 //表示账号8位

#define PN 7 //表示密码6位

#define ASN 3 //表示系统中共有3个账户信息

struct Account

{

char accountnumber[AN]//表示账号信息

char password[PN]//表示账户的密码信息

double balance //表示账户的余额

}

struct Account ats[ASN]={{"00000001","123456",100},{"00000002","123456",200},{"00000003","123456",300}}

//ats数组用于存储系统中三个账户的信息

int isCorrect(char *an,char *psd)

{

int i

for(i=0i<ASNi++)

if(strcmp(ats[i].accountnumber,an)==0 &&strcmp(psd,ats[i].password)==0)

return 1

return 0

}

double getBalance(char *an)

{

int i

for(i=0i<ASNi++)

if(strcmp(an,ats[i].accountnumber)==0)

return ats[i].balance

}

void deposit(char *an,int amount)

{

int i

for(i=0i<ASNi++)

if(strcmp(an,ats[i].accountnumber)==0)

ats[i].balance+=amount

}

int withdraw(char *an,int amount)

{

int i

for(i=0i<ASNi++)

if(strcmp(an,ats[i].accountnumber)==0)

return ats[i].balance-=amount

}

void main()

{

char AccountNumber[AN]={'\0'}

char psd[PN]={'\0'}

int i,errorcount=0

while(1)

{

printf("\n请输入8位账号:")

for(i=0i<8i++)

AccountNumber[i]=getch()

printf("\n请输入6为密码:")

for(i=0i<6i++)

{

psd[i]=getch()

putchar('*')

}

if(isCorrect(AccountNumber,psd)==1)

{

int tag,amount

while(1)

{

printf("\n欢迎登录银行账户管理系统,请选择您要的服务:1、查询余额;2、存款 *** 作;3、取款 *** 作;4、退出系统\n")

scanf("%d",&tag)

switch(tag)

{

case 1:

printf("您现在的余额为%f元\n",getBalance(AccountNumber))

break

case 2:

printf("请输入您的存款金额:")

scanf("%d",&amount)

deposit(AccountNumber,amount)

printf("存款成功!您的当前余额为:%f元\n",getBalance(AccountNumber))

break

case 3:

printf("请输入您的取款金额:")

scanf("%d",&amount)

if(amount<=getBalance(AccountNumber))

printf("取款成功!您的当前余额为:%f元\n",withdraw(AccountNumber,amount))

else

printf("取款失败!\n")

break

case 4:

break

}

if(tag==4)

break

}

}

else

{

errorcount++

if(errorcount==3)

{

printf("您已经连续三次输入错误,系统将自动关闭\n")

break

}

}

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/7736200.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-09
下一篇2023-04-09

发表评论

登录后才能评论

评论列表(0条)

    保存