请编写程序,上机调试,题目如下图,请按题目要求编写,并给出程序
3条回答 默认 最新
- qfl_sdu 2022-11-01 12:04关注
运行结果:
代码:
#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; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录
悬赏问题
- ¥15 2020长安杯与连接网探
- ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
- ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
- ¥16 mybatis的代理对象无法通过@Autowired装填
- ¥15 可见光定位matlab仿真
- ¥15 arduino 四自由度机械臂
- ¥15 wordpress 产品图片 GIF 没法显示
- ¥15 求三国群英传pl国战时间的修改方法
- ¥15 matlab代码代写,需写出详细代码,代价私
- ¥15 ROS系统搭建请教(跨境电商用途)