用C++编写相关程序4

请编写程序,上机调试,题目如下图,请按题目要求编写,并给出程序,答案是540!

img

印象里写过的啊

#include <iostream>
using namespace std;

class Bank
{
protected:
    double interest;
    int year;
    double money;
    double rate;
public:
    Bank() {}
    Bank(int year,double money)
    {
        this->year = year;
        this->money = money;
        this->rate = 0.035;
        interest = Cal_Interest();
    }
    virtual double Cal_Interest() 
    {
        return year * money *rate;
    }
    double getInterest() {return interest;}
};

class ConstructionBank : public Bank
{
protected:
    double year;
    double dayrate;
public:
    ConstructionBank() {}
    ConstructionBank(double year,double money) : Bank((int)year,money)
    {
        this->year = year-int(year);
        dayrate = 0.00015;
        interest = Cal_Interest();
    }
    virtual double Cal_Interest() {return Bank::Cal_Interest() + year * dayrate * money * 1000;}

};

class XMBank : public Bank
{
protected:
    double year;
    double dayrate;
public:
    XMBank() {}
    XMBank(double year,double money) : Bank((int)year,money)
    {
        this->year = year-int(year);
        dayrate = 0.0001;
        interest = Cal_Interest();
    }
    virtual double Cal_Interest() {return Bank::Cal_Interest() + year * dayrate * money * 1000;}
    void Set_large_deposit(double money,double rate,double dayrate)
    {
        if(money >= 200000)
        {
            this->rate = rate;
            this->dayrate = dayrate;
        }
    }
};

int main()
{
    ConstructionBank cb(5.216,50000);
    double ck = cb.getInterest();
    XMBank xb(5.216,50000);
    double xk = xb.getInterest();
    printf("%.2lf",ck-xk);
    return 0;
}