⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mog.cc

📁 C++ source code for book-C++ and Object Oriented Numeric computing for scientists and engineers
💻 CC
字号:
// This program computes monthly payment of a fixed
// rate mortgage. It computes correctly in the sense that
// it produced exactly the same result as my mortgage.

#include <iostream>

double mnpay(double tsum, double mrate, int tmonths) {

  // it returns the monthly payment of a fixed rate
  // mortgage of amount "tsum" with
  // rate "mrate" and total months "tmonths" of length

  std::cout << "mortgage rate  = " << mrate << " percent\n";
  std::cout << "mortgage amount   = " << tsum << '\n';
  std::cout << "length of mortgage in months = " << tmonths << '\n';
  std::cout << "length of mortgage in years = " << tmonths/12.0 << '\n';

  long double tmp = 1.0/(1.0 + 0.01*mrate/12.0); 
  long double u = 1;
  for (int i = 1; i < tmonths; i++) u = 1 + tmp*u; 
  u = tmp*u;
  return tsum/u;
}

int  main () {
  // for a 15 year mortgage of $200000 with rate 6.25%.
  double mp= mnpay(200000, 6.25, 15*12);
  std::cout << "monthly payment = " << mp << '\n';
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -