敲代码的第十天:储蓄账户版本二(c++)

        

#include<iostream>
#include<string>
using namespace std;
class BaseAccount
{
public:
   static long money;
   const long num;
public:
  BaseAccount():num(888666)
  {
   cout<<"请输入六位银行账户:";
   long num1;
   while(1)
   {
 cin>>num1;
 if(num==num1)
 {
  cout<<"账号输入成功!"<<endl;
  break;
 }
 else
  cout<<"账号输入失败,请再次输入:";
   }
  }
  void output()
  {
   cout<<"账户存款为:";
   cout<<money<<endl;
  }
};
long BaseAccount::money=0;
class StorageAccount:public  BaseAccount
{
public:
 long num2;
 string address;
public:
  friend istream& operator >> (istream& cin,StorageAccount& c);
  friend ostream& operator << (ostream& cout,StorageAccount& c);
  StorageAccount():num2(111222),address("huxian")
  {
   cout<<"请输入六位账号密码:";
   while(1)
   {
 long num3;
 cin>>num3;
 if(num2==num3)
 {
  cout<<"密码正确,请继续您的操作"<<endl;
  break;
 }
 else
  cout<<"密码错误请重新输入:";
   }
  }
  void intput(long C1)
  {
    money+=C1;
  }
  void output1(long C2)
  {
   money-=C2;
   if( money<=0)
   {
    cout<<"余额不足"<<endl;
    money+=C2;
   }
  }
};
istream& operator >> (istream& cin,StorageAccount& c){return cin>>c.num2;}
ostream& operator << (ostream& cout,StorageAccount& c){return cout<<c.address;}

void test1()
{
 cout<<"请选择你的操作:"<<endl;
 cout<<"1.存款"<<endl;
 cout<<"2.取款"<<endl;
 cout<<"3.退出"<<endl;
 cout<<"4.修改密码"<<endl;
 cout<<"5.显示账户信息"<<endl;
 cout<<".............................."<<endl;
}

StorageAccount S1;
void test2()
{
 long T;
 cout<<"请输入原密码:";
 while(1)
 {
  cin>>T;
  if(S1.num2==T)
  {
   cout<<"密码输入正确,请输入新密码:";
   cin>>S1.num2;
   cout<<"密码修改成功!"<<endl;
   break;
  }
  else
   cout<<"密码错误,请重新输入:";
 }
 cout<<"-----------------------------"<<endl;
}

void test3()
{
 cout<<"账户地址为:"<<S1.address<<endl;
 cout<<"账户余额为:"<<S1.money<<endl;
 cout<<"账户利率为:2.88%"<<endl;
 cout<<"---------------------------------"<<endl;
}

void test4()
{
 while(1)
 {
 test1();
 long B;
 cin>>B;
 if(B==1)
 {
  long B1;
  cout<<"请输入存款金额:";
  cin>>B1;
  S1.intput(B1);
  S1.output();
  cout<<".............................."<<endl;
 }
 if(B==2)
 {
  long B2;
  cout<<"请输入取款金额:";
  cin>>B2;
  S1.output1(B2);
  S1.output();
  cout<<".............................."<<endl;
 }
 if(B==3)
 {
  cout<<"退出成功"<<endl;
  break;
 }
 if(B==4){test2();}
 if(B==5){test3();}
 }
}

int main()
{
 test4();
 return 0;
}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值