C++实现在一个类中写私有的成员变量,并包括相应的成员函数:一个返回初始余额;一个返回到期时的余额;一个返回利率;另一个返回存期。写一个构造将所有成员变量设为任何指定的值,同时包括一个默认构造函数。

    实现在一个类中写私有的成员变量,并包括相应的成员函数:一个返回初始余额;一个返回到期时的余额;一个返回利率;另一个返回存期。写一个构造将所有成员变量设为任何指定的值,同时包括一个默认构造函数。

其具体实现代码如下:

#include<iostream>
using namespace std;

class CDAccount
{
public:
 CDAccount();
 CDAccount(double blce1, double rate, int term);
 double getBanlance1();
 double getBanlance2();
 double getRate();
 int getTerm();

private:
 double balance;
 double interestRate;
 int term;
};

CDAccount::CDAccount()
{
 balance = 0;
 interestRate = 0;
 term = 0;
}
CDAccount::CDAccount(double blce1, double rate, int term1)
{
 balance = blce1;
 interestRate = rate;
 term = term1;
}

double CDAccount::getBanlance1()
{
 return balance;
}

double CDAccount::getRate()
{
 return interestRate;
}

int  CDAccount::getTerm()
{
 return term;
}

double CDAccount::getBanlance2()
{
  balance = getBanlance1() + getBanlance1()*getRate()*getTerm();
 return balance;
}
int main()
{
 CDAccount account1(1,1,10);
 double blce11, rate;
 int term;
 cout << "请输入初始余额:" << account1.getBanlance1() << endl;
 cout << "请输入返回利率:" << account1.getRate() << endl;
 cout << "请输入返回存期:" << account1.getTerm() << endl;
 cout << "到期时的余额为:" << account1.getBanlance2() << endl;
 return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值