📄 5vii.cpp
字号:
// FILE: finance.cpp
#include <math.h>
// RateExpr() Return an interest sub-expression
// IN: rate is the periodic interest rate
// k is a payment number
float RateExpr (float rate, float k)
{ float temp;
temp = 1.0 + rate;
return (pow (temp, -k));
}
// Payment() Return the payment on a loan given the prin-
// ciple, rate, and number of payments
// IN: rate is the periodic interest rate
// principal is the original loan value
// num_payments is the number of equally-spaced payments
float Payment (float principal, float rate, float num_pay)
{ float paymnt;
paymnt = principal * (rate / (1.0 - RateExpr (rate, num_pay)));
return (paymnt);
}
// Amortize() Update the accumulated interest and balance
// of a loan given principal, rate, payment, and payment number
// IN: rate is the periodic interest rate
// prin is the original loan value
// num is the current payment number
// OUT: bal is the current loan balance after the current payment
// accum is the accumulated interest after payment
void Amortize (float& accum, float& bal, float rate, float pmnt,
float prin, float num)
{ float temp;
temp = RateExpr (rate, num);
bal = (1.0 / temp) * (pmnt * (temp / rate) + prin);
accum = bal + num * pmnt - prin;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -