2021-05-30

实现一个银行账号类

功能与现实生活中的atm机相似
在这里插入图片描述

以下为代码:
#include
#include"bank.h"
#include
#include
#include
#include
#include

using namespace std;
int find(string zhanghao,vector v1);
int main ()
{
//read the bank account information
ifstream fin1;
ofstream fout1;
ofstream fout2;
fout1.clear();
fout1.open(“bankAccount_log.txt”,ios_base::app);
fin1.open(“bankAccount.csv”);
string s9,s8;
getline(fin1, s9);
vector info;
while(getline(fin1,s9))
{
int n = s9.size();
for (int i = 0; i < n; ++i){
if (s9[i] == ‘,’){
s9[i] = ’ ';
}
}
istringstream out(s9);
while(out>>s8)
info.push_back(s8);

    }

// 假设以下容器中的对象为所有的银行卡账号
vector v1;
for(int i = 0 ; i < (info.size()/6) ; i++)
{
Bank a ;
a= Bank(info[6i],info[6i+1],info[6i+2],info[6i+3],info[6i+4],info[6i+5]);
v1.push_back(a);
}

//打印界面
string s=“hello world”;
while(s!=“q”)
{
cout<<“welcome to China Bank!”<<endl;
cout<<“Please enter your account”<<endl;
string password1;
int flag = 0;
cin >> s;
if(s==“q”){
break;
}
int target = find(s,v1);
while(target== -1)
{
cout<<“The account you entered is not exist.\n”<<
“please try again.\n”;
cin>>s;
target = find(s,v1);
}
cout<<“Please enter your password”<<endl;
for(int i=0 ; i<3&&v1[target].showState() ; i++)
{
cin >> password1;
if(password1 == v1[target].repass())
{
flag = 1;
break;
}
else
{
cout<<“Please enter the true password.”<<endl;
}
}
if(flag == 0){
cout<<“You have entereed your password three times wrong”
<<" and you card will be lock.If you have any problems,"
<<“please contact our worker in time.”;
v1[target].set_state(false);
}
else
{
cout<<“Main menu:”<<endl;
cout<<" 1.View my balance"<<endl;
cout<<" 2.Withdraw cash"<<endl;
cout<<" 3.Deposite funds"<<endl;
cout<<" 4.Transfer funds"<<endl;
cout<<" 5.Change the password"<<endl;

    cout<<"    6.Exit"<<endl;
    int i = 0;
    int num,numd,target2,num1;
    string ss1;
    string pas1,pas2;




    while( i != 6)
    {
        cin>>i;
        switch(i)
        {
        case 1: v1[target].show();break;

        case 2: 
            cout<<"Please enter how much monney you want to withdraw :"<<endl;
            cin>>num;
            if(num>=v1[target].reonce_limit()&&num>=v1[target].showBalance())
                cout<<"The number you want to deposite has over the limit."<<endl;
            else
                v1[target].WithDraw(num);
                fout1<<v1[target].reaccount()<<":"<<endl;
                fout1<<"Withdraw monney of "<<num<<endl;
                fout1<<"THere is "<<v1[target].showBalance()<<"to be left"<<endl;
            
            break;

        case 3:
            cout<<"Please enter how much monney you want to deposit :"<<endl;
            cin>>numd;
            v1[target].Deposit(numd);
            fout1<<v1[target].reaccount()<<":"<<endl;
            fout1<<"deposit monney of "<<numd<<endl;
            fout1<<"THere is "<<v1[target].showBalance()<<"to be left"<<endl<<endl;;
            break;

        case 4: 
            cout<<"Please enter the account you want to transfer :"<<endl;
            
            cin>>ss1;
            target2 = find(ss1,v1);
            while(target2== -1)
                { 
                    cout<<"The account you entered is not exist.\n"<<
                    "please try again.\n";
                    cin>>ss1;
                    target2 = find(ss1,v1);
                }
            cout<<"The number you want to transfer :";
            
            cin>>num1;
            if(num1<=v1[target].reonce_limit())
            {
                v1[target2].Deposit(num1);
                fout1<<v1[target2].reaccount()<<":"<<endl;
                fout1<<"deposit monney of "<<num1<<endl;
                fout1<<"THere is "<<v1[target2].showBalance()<<"to be left"<<endl<<endl;

                v1[target].WithDraw(num1);
                fout1<<v1[target].reaccount()<<":"<<endl;
                fout1<<"Withdraw monney of "<<num<<endl;
                fout1<<"THere is "<<v1[target].showBalance()<<"to be left"<<endl<<endl;
            }
            else
            {
                cout<<"The number is over the limit ,you can't transfer it"<<endl;
            }
            break;
        
        case 5: 
            cout<<"Please enter the new password!"<<endl;
            
            cin>>pas1;
            cout<<"Please enter the new password again!"<<endl;
            cin>>pas2;
            if(pas1==pas2)
                v1[target].resetPasswords(pas1);
            cout<<"You have change the password sucessfully!"<<endl;
            break;

        
        }
    



    }

}

}
//更改账户信息
fout2.clear();
fout2.open(“bankAccount.csv”);
fout2 <<“账号”<<’,’<<“名字”<<’,’<<“余额”<<’,’<<“身份证”<<’,’<<“密码”<<’,’<<“状态”<<endl;
for(int i=0; i<v1.size(); i++)
{
fout2 <<v1[i].reaccount()<<’,’<<v1[i].rename()<<’,’<<v1[i].showBalance()
<<’,’<<v1[i].reid()<<’,’<<v1[i].repass()<<’,’<<v1[i].restate()<<endl;
}
return 0;

}
int find(string zhanghao,vector v1)
{
for(int i=0;i<v1.size();i++)
{
if(v1[i].reaccount() == zhanghao)
return i;
}
return -1;
}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程?小白

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值