ycy支付宝和余额宝 DeBug



待更新!

#include<iostream>
#include <string>
using namespace std;

class Account{
protected:
    long ID;
    string name;
public:
    Account(long id,string n)
    {ID=id;name=n;}
    long get_ID(){return this->ID;}
    string get_name(){return this->name;}
};
class AliPay:protected Account{
protected:
    double amount;
    int out_limit;//支付宝转账上限,资金转出不得超出账户中金额也不能超出上限
    //当转账要求超出上述限制时,自动转出最大允许金额
public:
    AliPay(long id,string n,double a,int out)
    :Account(id,n),amount(a),out_limit(out)
    {}
    long get_ID(){return this->ID;}
    string get_name(){return this->name;}
    double get_AliPay_amount(){return this->amount;}
    int get_out_limit(){return this->out_limit;}
    void AliPay_add(double add){this->amount+=add;}
    void AliPay_reduce(double reduce){this->amount-=reduce;}
};
class AliFund:protected Account{
protected:
    double amount;
    double rate;//余额宝账户中资金年利率
    int in_limit;//余额宝转账下限,资金转入余额宝时不得少于该下限,上不封顶
    //当转入资金不足下限金额时,自动忽略该资金转入操作,资金退回
public:
    AliFund(long id,string n,double a,double r,int in)
    :Account(id,n),amount(a),rate(r),in_limit(in)
    {}
    double get_AliFund_amount(){return this->amount;}
    double get_rate(){return this->rate;}
    int get_in_limit(){return this->in_limit;}
    void AliFund_add(double add){this->amount+=add;}
    void AliFund_reduce(double reduce){this->amount-=reduce;}
};
class My_Ali
:public AliPay,public AliFund{
protected:
    bool auto_collect_flag;//资金自动收集标志
    int threshold;//资金自动收集阈值
    //若资金自动收集标志为true,当用户支付宝账户金额超过资金自动收集阈值threshold时,
    //超过且符合支付宝账户资金转出限制和余额宝资金转入下限的部分资金将自动转入余额宝中
public:
    My_Ali(long id,string n,double pa,int out,double fa,double r,int in)
    :AliPay(id,n,pa,out),AliFund(id,n,fa,r,in)
    {}
    void set_flag(bool flag){this->auto_collect_flag=flag;}
    void set_threshold(int th){this->threshold=th;}
    void AliPay_add(double add)
    {
        AliPay::AliPay_add(add);
        auto_collect();
    }
    void Pay_to_Fund(double P2F)
    {
        if(P2F>get_out_limit())P2F=get_out_limit();
        if(P2F>=get_in_limit())
        {
            AliFund_add(P2F);
            AliPay_reduce(P2F);
        }
    }
    void Fund_to_Pay(double F2P)
    {
        AliFund_reduce(F2P);
        AliPay_add(F2P);
        auto_collect();
    }
    void auto_collect()
    {
        double ex=get_AliPay_amount()-threshold;
        if(ex>get_in_limit()&&auto_collect_flag)Pay_to_Fund(ex);
    }
};
int main()
{
// 第一个数据是账号,第二个字符串是用户名,第三个数据是支付宝初始金额,
// 第四个数据是支付宝转账上限,第五个数据是余额宝初始金额,第六个数据是余额宝资金年利率,
// 第七个数据是余额宝转账下限,第八个数据是资金自动收集标志,字符Y代表设置资金自动收集,字符N代表不设置资金自动收集。
// 若设置资金自动收集,第九个数据是资金自动收集阈值
    long ID;
    string name;
    double Pamount,Famount,rate;
    int out,in,threshold;
    char flag;
    cin>>ID>>name>>Pamount>>out>>Famount>>rate>>in>>flag;
    My_Ali ycy(ID,name,Pamount,out,Famount,rate,in);
    if(flag=='Y')
    {
        cin>>threshold;
        ycy.set_flag(1);
        ycy.set_threshold(threshold);
    }
    else ycy.set_flag(0);
// 第一个数字代表当前操作的账户类型,1代表支付宝账户,2代表余额宝账户,
// 第二个数字代表具体操作,1代表账户资金增加,2代表账户金额减少,3代表支付宝和余额宝之间的资金转移,
// 第三个数字代表操作金额。
    int type,op;
    double num;
    while(1)
    {
        cin>>type>>op>>num;
        if(type==0)break;
        else if(type==1)
        {
            if(op==1)ycy.AliPay_add(num);
            else if(op==2)ycy.AliPay_reduce(num);
            else ycy.Pay_to_Fund(num);
        }
        else
        {
            if(op==1)ycy.AliFund_add(num);
            else if(op==2)ycy.AliFund_reduce(num);
            else ycy.Fund_to_Pay(num);
        }
    }
    cout<<"Account for "<<ycy.AliPay::get_name()<<endl;
    cout<<"Total: "<<ycy.get_AliPay_amount()+ycy.get_AliFund_amount()<<endl;
    cout<<"AliPay: "<<ycy.get_AliPay_amount()<<endl;
    cout<<"AliFund: "<<ycy.get_AliFund_amount()<<" with rate "<<ycy.get_rate()*100<<"%";
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

赤城封雪

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

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

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

打赏作者

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

抵扣说明:

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

余额充值