特级茶叶 2022-11-01 11:07 采纳率: 78.6%
浏览 105
已结题

用C++编写相关程序3

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

img

  • 写回答

3条回答 默认 最新

  • qfl_sdu 2022-11-01 12:04
    关注

    运行结果:

    img

    代码:

    
    
    #include <iostream>
    using namespace std;
    
    class Bank
    {
    protected:
        double interest; //利息
        int year;
        double money;
        double rates; //利率
    public:
        Bank(int y, double m, double r) { year = y,money = m; rates = r; }
    
        void Cal_interest()
        {
            interest = year * money * rates;
            //cout << "parent Cal..." << endl;
            //return interest;
        }
        double GetInterest() { return interest; }
    };
    
    class ContructionBank:public Bank
    {
    private:
        double year;
        double rates;
    public:
        ContructionBank(double y, double m, double ry,double rd) :Bank((int)y, m, ry)
        {
            year = y;
            rates = rd;
        }
        void Cal_interest()
        {
            Bank::Cal_interest();
            //cout << "Constructbank Cal..." << endl;
            //得到天数
            double t = this->year - Bank::year;
            while ((t-(int)t) > 0.00001)
            {
                t *= 10;
            }
            //天利息
            double r2 = (int)t * money * this->rates;
            //
            interest = GetInterest() + r2;
            //return interest;
        }
    };
    
    class XMBank :public Bank
    {
    private:
        double year;
        double rates;
        double largemoney; //大额
    public:
        XMBank(double y, double m, double ry, double rd) :Bank((int)y, m, ry)
        {
            year = y;
            rates = rd;
        }
        void Cal_interest()
        {
            Bank::Cal_interest();
            //cout << "XMbank Cal..." << endl;
            //得到天数
            double t = this->year - Bank::year;
            while ((t - (int)t) > 0.00001)
            {
                t *= 10;
            }
            //天利息
            double r2 = (int)t * money * this->rates;
            //
            interest = GetInterest() + r2;
            //return interest;
        }
        void Set_large_deposit(double m, double yr, double dr)
        {
            if (money >= m)
            {
                Bank::rates = yr;
                this->rates = dr;
            }
        }
    };
    
    int main()
    {
        ContructionBank cb(5.216, 50000, 0.035, 0.0001);
        XMBank xb(5.216, 50000, 0.035, 0.00015);
        xb.Set_large_deposit(20, 0.04, 0.00018);//大额存款
        cb.Cal_interest();
        xb.Cal_interest();
    
        double cbr = cb.GetInterest();
        double xbr = xb.GetInterest();
        cout <<"5万元存5年零216天,在建行和厦门银行的利率差为:" << cbr - xbr << endl;
        return 0;
    }
    
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 11月9日
  • 已采纳回答 11月1日
  • 创建了问题 11月1日

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化