您的位置:首页 > 编程语言

银行ATM机工作流程模拟编程(代码)

2015-09-20 09:45 295 查看
#include<stdio.h>
#include<stdlib.h>
#include <conio.h>
#include <string.h>

void denglu(struct people *head,struct people *p);
void jiemian(struct people *head,struct people *p);
void chaxun(struct people *head,struct people *p);
void qukuan(struct people *head,struct people *p);
void cunkuan(struct people *head,struct people *p);
void xiugai(struct people *head,struct people *p);
void tuika(struct people *head,struct people *p);
void xinxi(struct people *head,struct people *p);

struct people
{
char name[10];
char account[20];
char password[10];
float money;
struct people*next;
};

void main()
{
int i,z,a,t=0;
char account[20],password[10],ch;
struct people *head,*p;
FILE *fp=fopen("1.txt","r");
head=NULL;

if(fp==NULL){printf("系统出错");return 1;}
for(i=0;i<5;i++)
{
p=(struct people*)malloc(sizeof(struct people));
fscanf(fp,"%s%s%s%f",p->name,p->account,p->password,&(p->money));
p->next=head;
head=p;
}
fclose(fp);
printf("***********欢迎使用ATM自动取款机***********\n");
printf("*******************************************\n");
denglu(head,p);

}

void denglu(struct people *head,struct people *p)
{
int a;
char account[20];
int i=0,t=0;
char password[10],ch;
printf("请输入卡号:");
scanf("%s",account);
//scanf("account:%s\npassword:",account);
for(a=0;a<5;a++)
{
if(strcmp(account,p->account)==0)
{

printf("请输入密码:");
while(1)
{
while((ch=getch())!='\r')
{
password[i++]=ch;
putchar('*');
}
password[i]='\0';
t++;
if(strcmp(password,p->password)==0)
{
system("cls");
printf("\n欢迎使用本系统!\n");
jiemian(head,p);
break;
}
else
{
if(t<3)
{
printf("\n密码错误,请重新输入:");
i=0;
}
else
{
printf("\n对不起,你无权使用本系统! 退出系统!\n");
for(i=0;i<1000000000;i++);
system("cls");
main();
}
}
}

}
else p=p->next;

}
}

void jiemian(struct people *head,struct people *p)
{
int z;
printf("1-----------个人信息\n");
printf("2-----------查询余额\n");
printf("3---------------取款\n");
printf("4---------------存款\n");
printf("5-----------修改密码\n");
printf("0---------------退卡\n");
while(1)
{
printf("\n请输入序号:");
scanf("%d",&z);
switch(z)
{
case 1:system("cls");xinxi(head,p);break;
case 2:system("cls");chaxun(head,p);break;
case 3:system("cls");qukuan(head,p);break;
case 4:system("cls");cunkuan(head,p);break;
case 5:system("cls");xiugai(head,p);break;
case 0:system("cls");tuika(head,p);break;
default:printf("操作序号不合法!!!");
return ;
}
}
}

void xinxi(struct people *head,struct people *p)
{
char gg;
printf("***********************************************\n");
printf(" 用户名:%s\n",p->name);
printf(" 帐号:%s\n",p->account);
printf("***********************************************\n");
printf("按任意键返回菜单,按N键退卡!\n");
if(gg=getch()=='n')
{system("cls");tuika(head,p);}
else
{system("cls");jiemian(head,p);}
}

void chaxun(struct people *head,struct people *p)
{
char gg;
printf("余额:%7.2f元\n",p->money);
printf("按任意键返回菜单,按N键退卡!\n");
if(gg=getch()=='n')
{system("cls");tuika(head,p);}
else
{system("cls");jiemian(head,p);}
}

void qukuan(struct people *head,struct people *p)
{
char gg;
float a;
struct people *f;
FILE *fp=fopen("1.txt","w+");
printf("请输入取款金额:");
scanf("%f",&a);
if(a>p->money)
printf("余额不足!");
else
{
printf("成功取款%7.2f元\n",a);
p->money=p->money-a;
f=head;
while(f!=NULL)
{
fprintf(fp,"%s\t%s\t%s\t%f\n",f->name,f->account,f->password,p->money);
f=f->next;
}
fclose(fp);
}
printf("按任意键返回菜单,按N键退卡!\n");
if(gg=getch()=='n')
{system("cls");tuika(head,p);}
else
{system("cls");jiemian(head,p);}

}

void cunkuan(struct people *head,struct people *p)
{
char gg;
float a;
struct people *f;
FILE *fp=fopen("1.txt","w+");
printf("请输入存款金额:");
scanf("%f",&a);
printf("成功存款%7.2f元\n",a);
p->money=p->money+a;
f=head;
while(f!=NULL)
{
fprintf(fp,"%s\t%s\t%s\t%f\n",f->name,f->account,f->password,f->money);
f=f->next;
}
fclose(fp);
printf("按任意键返回菜单,按N键退卡!\n");
if(gg=getch()=='n')
{system("cls");tuika(head,p);}
else
{system("cls");jiemian(head,p);}

}

void xiugai(struct people *head,struct people *p)
{
char gg;
char a[10],b[10],c[10];
struct people *f;
FILE *fp=fopen("1.txt","w+");
printf("请输入原密码:");
scanf("%s",a);
if(strcmp(a,p->password)==0)
{
printf("请输入新密码:");
scanf("%s",b);
printf("请再次输入新密码:");
scanf("%s",c);
if(strcmp(b,c)==0)
{
printf("密码修改成功!\n");
strcpy(p->password,b);

f=head;
while(f!=NULL)
{
fprintf(fp,"%s\t%s\t%s\t%f\n",f->name,f->account,f->password,f->money);
f=f->next;
}
fclose(fp);
}
else
printf("两次输入不同!\n");

}
else
{
printf("原密码输入错误!\n");
}

printf("按任意键返回菜单,按N键退卡!\n");
if(gg=getch()=='n')
{system("cls");tuika(head,p);}
else
{system("cls");jiemian(head,p);}
}

void tuika(struct people *head,struct people *p)
{
int i ;
printf("请取回您的磁卡");
for(i=0;i<1000000000;i++);
system("cls");
main();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: