请编写程序,上机调试,题目如下图,请按题目要求编写,并给出程序
运行结果:
代码:
#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;
}
都有类图了,兄弟哪方面有困难