特级茶叶 2022-11-04 14:23 采纳率: 78.6%
浏览 38
已结题

用C++编写相关程序4

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

img

  • 写回答

1条回答 默认 最新

  • 快乐鹦鹉 2022-11-04 14:26
    关注

    印象里写过的啊

    #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;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

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

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程