#include<iostream>
#include<cstring>
#include<cstdio>
#include<conio.h>
using namespace std;
class ATM
{
public : double a; //ATM机金额
public : char *n = new char[6]; //ATM机密码
private: double money=0;//限额500000
public :
void setpassword()
{
int j;
char m;
for (j=0;j<6;j ) //输入密码,并以*显示
{
B:
m=getch();
if(m<='9' && m>='0')
{
this->n[j]=m;
cout<<"*";
}
else
goto B;
}
cout<<"\n";
}
void setYuE(double m)
{
this->a=m;
}
char *password() //定义密码输入函数
{
int j;
char *n = new char[6]; //定义指向一个具有6个char类型数组的首地址
char m;
for (j=0;j<6;j )
{
B:
m=getch();
if(m<='9' && m>='0')
{
n[j]=m;
cout<<"*";
}
else
goto B;
}
cout<<"\n";
return n;
}
int login(char*m) //定义账户的登录函数
{
int i,j,k;
char *s;
cout<<" 登录 "<<endl;
cout<<"************"<<endl;
for (i=1;i<4;i ) //记录输错密码的次数
{
cout<<"请输入密码:"<<endl;
s=this->password();
for(j=0;j<4;j ) //判断密码是否输入错误
{
if(m[j]!=s[j])
{
cout<<"密码错误!"<<endl;
break;
}
}
if(j==4)
{
cout<<"登录成功!"<<endl;
break;
}
}
return i;
}
double YuE(double a) //定义余额查询函数
{
cout<<"当前余额:"<< a <<"元"<<endl;
return a;
}
double QuKuan(double a) //定义取款函数
{
int b;
while(1)
{
cout<<"请输入取款金额:"<<endl;
cout<<"(注意:金额需要100的整数倍,且在100~10000之间)"<<endl;
cin>>b;
if((b%100)!=0)
cout<<"输入错误,请重新输入"<<endl;
else if(b>10000)
cout<<"超出单笔限额,请重新输入"<<endl;
else if(b>a)
cout<<"余额不足,请重新输入"<<endl;
else if(this->money>500000)
{
cout<<"今日已经超出500000限额"<<endl;
return a;
}
else
{
this->money =b;
break;
}
}
cout<<"取款成功!"<<"请取走您的钞票"<<endl;
a-=b;
return a;
}
double CunKuan(double a) //定义存款函数
{
int b;
cout<<"请把钞票放入指定位置"<<endl;
while(1)
{
cout<<"请输入存款金额:"<<endl;
cin>>b;
if((b%100)!=0)
cout<<"输入错误,请重新输入"<<endl;
else break;
}
cout<<"存款成功!"<<"请注意查看!"<<endl;
a =b;
return a;
}
double ZhuanZhang(double a) //定义转账函数
{
char user[19];
char s1[20];
char s2[20];
double b;
while(1){
cout<<"请输入对方19位账号:"<<endl;
cin>>s1;
if(strlen(s1)!=19)
{
cout<<"账号不存在,请重新输入"<<endl;
}
else
break;
}
cout<<"请再次输入对方账号:"<<endl;
cin>>s2;
if(strcmp(s1,s2)!=0)
{
cout<<"两次账号输入不一致"<<endl;
return a;
}
while(1)
{
cout<<"请输入转账金额:"<<endl;
cin>>b;
if(b<0)
cout<<"输入错误,请重新输入"<<endl;
else if(b>a)
cout<<"金额不足,请重新输入"<<endl;
else if(this->money b>500000)
{
cout<<"今日已经超出500000限额"<<endl;
return a;
}
else
{
this->money =b;
break;
}
}
cout<<"转账成功!"<<"请及时查看!"<<endl;
a-=b;
return a;
}
char *MiMa(char m[6]) //定义修改密码的函数
{
int i,j,count=0;
char *s1=new char[6], *s2=new char[6], *s3=new char[6];
while(1)
{
cout<<"请输入旧密码:"<<endl;
s1=this->password();
for(i=0;i<6;i )
{
if(s1[i]!=m[i])
{
cout<<"密码错误!"<<endl;
break;
}
}
if(i==6)
{
cout<<"密码正确!"<<endl;
break;
}
}
A:
cout<<"请输入新密码:"<<endl;
s2=this->password();
cout<<"请在此输入新密码:"<<endl;
s3=this->password();
for(j=0;j<6;j )
{
if(s2[j]==s3[j])
{
count ;
}
}
if(count==6)
{
for(j=0;j<6;j )
{
this->n[j]=s2[j];
}
cout<<"密码修改成功!"<<endl;
return s2;
}
else
{
cout<<"两次输入不一致,请重新输入"<<endl;
goto A;
}
}
};
int main()
{
system("chcp 65001 && cls");
//freopen("1.txt","w",stdout);
FILE *p;
p=fopen("D:/cpp/sorce/1.txt","wb");
int a,i;
double balance=10000.0;
double balance2=balance;
char name[10],account[19],*word[6];
char idcard[18];
ATM atm;
cout<<"*******欢迎使用WLX牌ATM机********"<<endl;
cout<<"为了方便您的操作,请提供以下信息:\n"<<endl;
cout<<"请输入您的姓名:"<<endl;
cin>>name;
fprintf(p,"姓名为%s\n",name);
H:
cout<<"请输入您的账号:"<<endl;
cin>>account;
if(strlen(account)!=19)
{cout<<"账号格式有误,请重新输入"<<endl;
goto H; }
fprintf(p,"账号为%s\n",account);
id:
cout<<"请输入您的身份证号码"<<endl;
cin>>idcard;
if(strlen(idcard)!=18)
{cout<<"身份证格式有误,请重新输入"<<endl;
goto id; }
fprintf(p,"身份证为%s",idcard);
cout<<"请输入您的账号密码"<<endl;
atm.setpassword();
fprintf(p,"密码是%s\n",atm.n);
fprintf(p,"余额%f\n",balance);
atm.setYuE(balance);
cout<<"\n";
i=atm.login(atm.n);
if(i<4)
{
cout<<"\n";
cout<<"\n";
cout<<"账号:"<<account<<endl;
cout<<"姓名:"<<name<<endl;
cout<<"密码:"<<atm.n<<endl;
cout<<"余额:"<<balance<<endl;
cout<<"\n";
cout<<"\n";
}
if(i==4)
cout<<"密码错误三次,您的帐号已被冻结"<<endl;
else
{
cout<<"****ATM机为您服务****"<<endl;
cout<<"请选择交易类型对应编号"<<endl;
while(1)
{
cout<<"1-余额查询"<<endl;
cout<<"2-取款"<<endl;
cout<<"3-存款"<<endl;
cout<<"4-转账业务"<<endl;
cout<<"5-密码修改"<<endl;
cout<<"0-退卡"<<endl;
cin>>a;
if(a==0)
{
cout<<"退卡成功!"<<endl;
break;
}
else switch(a) //判断使用什么功能
{
case 1: atm.YuE(balance);break;
case 2: balance = atm.QuKuan(balance);
fprintf(p,"取款了-%f\n,余额%f\n",balance2-balance,balance);
balance2=balance;
break;
case 3: balance = atm.CunKuan(balance);
fprintf(p,"存款了 %f\n,余额%f\n",balance-balance2,balance);
balance2=balance;
break;
case 4: balance = atm.ZhuanZhang(balance);
fprintf(p,"转账了-%f,余额%f\n",balance2-balance,balance);
balance2=balance;
break;
case 5: *word=atm.MiMa(atm.n);
fprintf(p,"密码修改为%s\n",word);
break;
}
cout<<"\n是否继续"<<endl;
}
}
fclose(p);
return 0;
}
网友评论
我要评论