#include
#include
#include
#include
int temp,count;
FILE *fp,*fp1,*fp2,*fp3,*fp4;
struct {char account[18];char password[8];char name[8];int money1;char money2[6];}user[100]; //定义账户结构体
/****************************************/
/*返回主菜单*/
void ret()
{
temp=1;
do
{
printf("输入0返回主菜单\n");
scanf("%d",&temp);
}
while(temp);
}
/****************************************/
/*输入账户*/
void imp1(char *p)
{
printf("请输入16位数字的账号\n");
scanf("%s",p);
int n;
n=strlen(p);
while(n!=16)
{
printf("账号为16位数字,请重新输入\n");
scanf("%s",p);
n=strlen(p);
}
}
/****************************************/
/*输入密码*/
void imp2(char *p)
{
printf("请输入6位数字的密码\n");
scanf("%s",p);
int n;
n=strlen(p);
while(n!=6)
{
printf("密码为6位数字,请重新输入\n");
scanf("%s",p);
n=strlen(p);
}
}
/****************************************/
/*数字转字符*/
int change_a(int p,char *q)
{
int i=0;
while(p!=0)
{
q[i++]=p%10+'0';
p/=10;
}
int team1=0,team2=i-1;char temp;
while(team2>team1)
{
temp=q[team1];q[team1]=q[team2];
q[team2]=temp;team1++;team2--;
}
q[i]='\0';
return i;
}
/****************************************/
/*字符转数字*/
void change_b(int *p,char *q)
{
int i=0;
*p=0;
while(*q)
{
*p=*(q++)-'0'+10*(*p);
}
}
/****************************************/
/*查找账户*/
int look_for(char *zhanghu)
{
int i;
for(i=0;i<=count-1&&strcmp(zhanghu,user[i].account);i++)
{
if(i==count-1)
{
printf("您输入的账户不存在,请重新输入!!!\n");
imp1(zhanghu);i=-1;
}
}
return i;
}
/****************************************/
/*打印凭条*/
void record(int change1,int j)
{
char buf[6];
int change2=change1>=0?change1:-change1;
int i=change_a(change2,buf);
if(change2!=0)
{
fwrite(user[j].name,1,7,fp);
if(change1<0)
fwrite("取款",1,4,fp);
if(change1>0)
fwrite("存款",1,4,fp);
fwrite(buf,1,i,fp);
fwrite("元\n",1,3,fp);
}
}
/****************************************/
/*查询账户信息*/
void seek(int i)
{ printf("您的姓名为%s\n",user[i].name);
printf("您的账户密码为%s\n",user[i].password);
printf("您的账户目前余额为%d元\n",user[i].money1);
ret();
}
/****************************************/
/*存款*/
void add(int i)
{
temp=0;
int once,accum=0;
do
{
printf("请将钞票放入卡槽,");
do
{
printf("放钞完毕请按数字1确认\n");
scanf("%d",&temp);
}
while(temp!=1);
srand((unsigned)time(NULL));
once=rand()%21*100;
accum+=once; //累加存款总金额
printf("您本次放钞%d元,累计放钞%d元,继续放钞请按1,结束放钞请按0\n",once,accum);
scanf("%d",&temp);
while(temp!=0&&temp!=1)
{
printf("请输入0或1\n");
scanf("%d",&temp);
}
}
while(temp);
user[i].money1+=accum;
printf("累计放钞%d元,账户余额%d元\n",accum,user[i].money1);
record(accum,i);
ret();
}
/****************************************/
/*取款*/
void take(int i)
{int draw;
printf("请输入取款金额,取款金额只能是100的整数倍\n");
scanf("%d",&draw);
while(draw>user[i].money1||draw%100!=0)
{
while(draw%100!=0)
{
printf("取款金额只能是100的整数倍,请重新输入\n");
scanf("%d",&draw);
}
if(draw>user[i].money1)
{
printf("取款金额不能大于余额,请重新输入取款金额\n");
scanf("%d",&draw);
}
}
user[i].money1-=draw;printf("取款成功!!!请及时取走您的钞票\n");
printf("您本次取款金额为%d元,你的账户余额为%d\n",draw,user[i].money1);
record(-draw,i);
ret();
}
/****************************************/
/*打印凭条*/
void print()
{
fclose(fp);
printf("凭条已打印,请打开D\\交易明细.txt查看,每次交易只能被打印一次,请取走您的凭条后\n");
ret();
fp=fopen("D:\\文件\\交易明细.txt","w");
}
/****************************************/
/*创建新用户*/
void found()
{
printf("请输入新账户的账号\n");
imp1(user[count].account);
printf("请输入新账户的密码\n");
imp2(user[count].password);
user[count].money1=0;
do {
printf("请输入新账户的姓名(姓名不足三位请自动在末尾加两个空格\n");
scanf("%s",user[count].name);
}
while(user[count].name[6]!='\0');
count++;
printf("新用户创建成功,新用户的初始余额为0元\n");
}
/****************************************/
/*修改账户密码*/
void revision(int i)
{
printf("请输入账户的新密码\n");
imp2(user[i].password);
printf("修改密码成功\n");
}
/****************************************/
/*注销账户*/
void cancel(int i)
{
for(;i<=count-1;i++)
user[i]=user[i+1];
count--;
printf("注销账户成功\n");
}
/****************************************/
/*写入文本*/
void write()
{
fp1=fopen("D:\\文件\\账号.txt","w");
fp2=fopen("D:\\文件\\密码.txt","w");
fp3=fopen("D:\\文件\\姓名.txt","w");
fp4=fopen("D:\\文件\\余额.txt","w");
int i;
for(i=0;i0)
{
{
printf("密码输入错,误请重新输入\n连续3次密码输入错误,您的账号将被锁定,您还有%d次机会!!!\n",time--);
imp2(mima);
}
}
if(strcmp(mima,user[i].password)==0)
printf("密码输入正确!!!进入操作界面\n");
else
{
printf("您的账户已被锁定,已自动退出ATM机存取款系统!!!\n");
exit(0);
}
do
{
printf(" ________ \n");//菜单
printf(" |菜单栏| \n");
printf("---------------------------------------------\n");
printf("|输入数字1查看账户信息|输入数字2进行存款操作|\n");
printf("---------------------------------------------\n");
printf("|输入数字3进行取款操作|输入数字4查看交易明细|\n");
printf("---------------------------------------------\n");
printf("|输入数字5创建新用户 |输入数字6修改当前密码|\n");
printf("---------------------------------------------\n");
printf("|输入数字7注销账户 |输入数字8退出银行系统|\n");
printf("---------------------------------------------\n");
scanf("%d",&n);
switch(n)
{
default:printf("请重新输入一个数字\n");break;
case 1:seek(i);break; //查询
case 2:add(i);break; //存款
case 3:take(i);break; //取款
case 4:print();break; //打印
case 5:found();break; //开户
case 6:revision(i);break; //改密
case 7:cancel(i);break; //注销
case 8:printf("已成功退出系统,中国银行ATM取存款机欢迎您的使用\n");break;
}
}
while(n!=8);
write();
return 0;
}