|
4鱼币
以下代码是实现ATM转账功能的,不过运行的时候输入转账账号都显示不存在。
各位帮帮忙,看下是怎么一回事
#include<iostream>
#include<cstring>
#include<iomanip>
#include<string>
using namespace std;
class consumer
{
public:
friend class bank;
void set2(string c,string ch,string mm,int y)
{
ic=c;
chuhu=ch;
mima=mm;
yue=y;
}
int xiugai();//修改密码
void chaxun();//查询余额
int qukuan();//取款
int zhuanzhang();//转账
string getch();//取用户
string getmm();//取密码
private:
string chuhu;//储户
string ic;//卡号
string mima;//密码
int jine;//金额
int yue;//账户余额
};
class bank
{
public:
consumer c[5];
void set(int i,string id,string n,string ma,int m)
{
num=i;
idcard=id;
name=n;
mmi=ma;
money=m;
c[i].set2(id,n,ma,m);
};
void menu();
private:
string idcard,name,mmi;
int money,num;
};
void bank::menu()//菜单界面
{
cout<<"````````````````````````````````````"<<endl<<endl;
cout<<"***^.^欢迎进入自动取款机^.^***"<<endl<<endl;
cout<<"`````````````````````````````````````"<<endl<<endl;
cout<<"-*-*-*-*-*-*请输入登陆账号-*-*-*-*-*-*"<<endl;
string ch;
cin>>ch;
int i=0;
while((ch!=c[i].getch()))//判断该储户是否存在
i++;
if(i>=5)
{
cout<<endl<<endl;
cout<<"!.! o>.<O !.!"<<endl;
cout<<"~~~该账户不存在~~~"<<endl;
cout<<"-_-# ?_? -_-#"<<endl;
exit(0);//结束程序
}
cout<<endl<<"请输入登陆密码:";
string mi;
cin>>mi;
cout<<endl<<endl;
if(mi!=c[i].getmm())
{
cout<<endl<<endl;
cout<<"#############################"<<endl;
cout<<"你输入的密码有误,禁止继续使用"<<endl;
cout<<"#############################"<<endl;
exit(0);//结束程序
}
do
{
cout<<endl;
cout<<"请选择操作功能:"<<endl;
cout<<"1.修改密码功能;2.余额查询功能;3.取款功能;4.转账功能"<<endl<<endl;
int f;
cin>>f;
switch(f)
{
case 1:c[i].xiugai( );break;
case 2:c[i].chaxun( );break;
case 3:c[i].qukuan( );break;
case 4:c[i].zhuanzhang( );break;
}
cout<<endl<<endl<<"*******************"<<endl;
cout<<"是否继续使用 ~~^_^~~ "<<endl<<"1.继续;0.结束"<<endl;
cout<<"*******************"<<endl<<endl;
cout<<"请选择"<<endl;
int i;
cin>>i;
}while(1);
cout<<"*******谢谢^^^^^^^使用********"<<endl;
cout<<"***^.^请取卡,欢迎下次使用^.^***"<<endl;
}
int consumer::zhuanzhang()
{
cout<<endl<<endl<<"^(oo)^ ^(oo)^ ^(oo)^"<<endl<<endl;
cout<<"**你当前进入的是转账功能界面**"<<endl<<endl;
cout<<"请输入要转账到的储户:";
string ch;
cin>>ch;//转账到的储户
int i=0;
consumer c[5];
while((ch!=c[i].getch())&&(i<5))//判断该储户是否存在
i++;
if(i<5)
{
cout<<endl<<"请输入转账金额:";
cin>>jine;
c[i].yue=c[i].yue+jine;
cout<<"^(oo)^ ^(oo)^ ^(oo)^"<<endl<<endl;
cout<<"转账成功"<<endl<<endl;
cout<<"^(oo)^ ^(oo)^ ^(oo)^"<<endl<<endl;
return 1;
}
else
{
cout<<endl<<endl<<"!.! !>.<! !.!"<<endl<<endl;
cout<<"该储户不存在"<<endl<<endl;
cout<<"!.! !>.<! !.!"<<endl<<endl;
cout<<"1:进行重新输入;2:进行退出该界面"<<endl;
int s;
cin>>s;
if(s==1)
{
cout<<"^(oo)^ ^(oo)^ ^(oo)^"<<endl<<endl;
zhuanzhang();
cout<<"^(oo)^ ^(oo)^ ^(oo)^"<<endl<<endl;
}
else
if(s==2)
return 1;//退出
}
}
int main()
{
bank bk;
bk.set(0,"1000","fhp","123456",100000);
bk.set(1,"1001","lzh","111111",200000);
bk.set(2,"1002","ljj","222222",300000);
bk.set(3,"1003","zhu","333333",40000);
bk.set(4,"1004","hih","444444",50000);
bk.menu();
return 0;
}
|
|