SOGO論壇

標題: 如何計算利率 [列印本頁]

作者: 轟轟轟    時間: 2010-1-26 23:58:04     標題: 如何計算利率

提示: 作者被禁止發言或禁止訪問或刪除帳號,本文內容已被系統自動屏蔽。
作者: huyoho2000    時間: 2010-1-27 21:29:23

複利公式參考:http://www.cubicpower.idv.tw/php/OnHand/MoneyMgm/Compounding.php

我下面寫的程式純粹是針對你的問題,因此程式的實用性與意義並不大喔! 程式公分為三個檔案:main.cpp Bank.cpp Bank.h

main.cpp

#include "Bank.h"
#include <iostream>

using namespace std;

int main(void)
{
        BankAccount John(1, 0.1, 120);
        cout << "John10年後需還(單位為萬):" << John.getNewBalance() << endl;

        BankAccount Mary(1, 0.035, 120);
        cout << "Mary10年後本金(單位為萬):" << Mary.getNewBalance() << endl;

        return 0;
}

Bank.cpp

#include <iostream>
#include "Bank.h"
#include "math.h"
using namespace std;

BankAccount::BankAccount(double b, double ir, int t) {
        balance = b;
        interestRate = ir;
        term = t;
}

double BankAccount::getNewBalance() {
        return pow(balance*(1 + interestRate), term);
}

Bank.h

#ifndef BANK_H
#define BANK_H
class BankAccount
{

  public:
    BankAccount(double b, double ir, int t);
    double getNewBalance();

  private:
    double balance;      //本金
    double interestRate; //利率,以年利率計算  
    int term;            //期數,以月計算

};
#endif

《 本帖最後由 huyoho2000 於 2010-1-27 21:46 編輯 》




歡迎光臨 SOGO論壇 (https://oursogo.com/) Powered by OURSOGO.COM