等额本息还款公式
来源:互联网 发布:linux ant java 打包 编辑:程序博客网 时间:2024/06/09 21:07
贷款计算基类:
#ifndef CLOANBASE_H_INCLUDED
#define CLOANBASE_H_INCLUDED
#include <fstream>
#include <string>
#include <exception>
class CLoanException : public std::exception
{
std::string m_str;
public:
CLoanException(const char* msg) throw()
{
m_str = msg;
}
~CLoanException() throw() {}
virtual const char* what() const throw()
{
return m_str.c_str();
}
};
/** /brief class CLoanBase
* Description; 计算贷款数据的基类
*/
class CLoanBase
{
public:
CLoanBase(){}
virtual ~CLoanBase()
{
}
/** /brief GetResult
* Descriptioin: 通过给定的本金金额,贷款月份及利率,将计算结果信息用输出数据流传出。
* @param srcAmount[in]: 本金金额
* @param iMonths[in]: 贷款月数
* @param fRate[in]: 贷款利率
* @param ofs[out]: 贷款信息明细
*/
virtual void GetResult(std::ofstream& ofs, double srcAmount = 0, int iMonths = 0, float fRate = 0) throw(CLoanException) = 0;
protected:
void ThrowException(const char* str) throw(CLoanException)
{
throw CLoanException(str);
}
};
#endif // CLOANBASE_H_INCLUDED
等额本息还款类声明:
#ifndef RETURNSAMEINTEREST_H_INCLUDED
#define RETURNSAMEINTEREST_H_INCLUDED
#include "LoanBase.h"
/** /brief class CReturnSameInterest
* Description: 等额本息还款类;
*/
class CReturnSameInterest : public CLoanBase
{
public:
CReturnSameInterest();
~CReturnSameInterest();
virtual void GetResult(std::ofstream& ofs, double srcAmount = 0, int iMonths = 0, float fRate = 0) throw(CLoanException);
};
#endif // RETURNSAMEINTEREST_H_INCLUDED
类实现:
#include "ReturnSameInterest.h"
#include <math.h>
CReturnSameInterest::CReturnSameInterest()
{
}
CReturnSameInterest::~CReturnSameInterest()
{
}
void CReturnSameInterest::GetResult(std::ofstream& ofs, double srcAmount, int iMonths, float fRate) throw(CLoanException)
{
if (0 == srcAmount || 0 == iMonths || 0 == fRate)
{
throw "Input parameter is invalid. Please check it!";
}
/*!< 每月还款本金额 */
double returnAmountPerMonth = srcAmount;
/*!< 每月还款利息 */
double returnInterestPerMonth = 0;
/*!< 月利率 */
float ratePerMonth = fRate / 12;
/*!< 循环计算当期还款额 */
/**
* 每月还款利息:贷款本金 * 月利率 * ((1 + 月利率) ^ 还款期数 - (1 + 月利率) ^ (当前期数 - 1)) / ((1 + 月利率) ^ 当前期数 - 1)
* 每月还款本金:贷款本金 * 月利率 * (1 + 月利率) ^ (当前期数 - 1) / ((1 + 月利率) ^ 还款期数 - 1)
*/
for (int i = 1; i < iMonths + 1; ++i)
{
double dbResult1 = pow((1 + ratePerMonth), iMonths);
double dbResult2 = pow((1 + ratePerMonth), (i - 1));
if (0 == dbResult1 - 1)
{
CLoanBase::ThrowException("Invalid parameter div number");
}
returnInterestPerMonth = srcAmount * ratePerMonth * (dbResult1 - dbResult2) / (dbResult1 - 1);
ofs << "每月还款利息为:" << returnInterestPerMonth << "元 每月还款本金为:";
returnAmountPerMonth = srcAmount * ratePerMonth * dbResult2 / (dbResult1 - 1);
ofs << returnAmountPerMonth << "元 每月还款额:" << returnInterestPerMonth + returnAmountPerMonth << "元" << std::endl;
}
}
- 等额本息还款公式
- 按月等额本息还款
- 有趣--等额本息还款
- 等额本息还款和等额本金还款计算公式的推导
- 等额本息还款和等额本金还款计算公式的推导
- 等额本息还款和等额本金还款计算公式的推导
- 等额本息 和 等额本金还款法
- 等额本息计算公式
- 等额本息还款法、等额本金还款法比较
- 等比序列的实际应用 —等额本息还款金额公式推导
- 等额本息公式背后的含义
- 实训java第二课 数据类型 进制 等额本息还款
- 等额本金和等额本息房贷公式推导
- 理财等额本息和等额本金计算公式
- 等额度本息还款法计算公式
- 等额本金、等额本息
- 写一个MySql存储过程实现房贷等额本息还款计算(另外附javascript代码)
- 等额本金和等额本息的区别(含计算公式)
- SSL与SET协议
- 无线通信原理及应用--阅读笔记一
- [Web新闻]美科技博客:web 2.0网站或已成为过去式 (图)
- 存储过程和T-SQL语句的执行计划重用性比较
- 关于AIX下的su不能使用环境变量问题的解决
- 等额本息还款公式
- VPN标准Ipsec和S-MIME
- Ext终于开始收费了
- 对称和非对称加密
- cannotcreate windows service for mysql.error:0
- 如何改变VC中控件间的TAB切换顺序
- 拖动无标题窗口
- JavaScript动态加载CSS的三种方法
- JSP的那些事儿(8)----最简单的Hibernate入门简介