#include <iostream>
#include <string>

using namespace std;

class SavingsAccount {
private:
    string owner;
    double balance;
    double annual_rate;
    int months;

public:
    SavingsAccount(string owner, double annual_rate, int months) {
        this->owner = owner;
        this->annual_rate = annual_rate;
        this->months = months;
        balance = 0.0;
    }

    void add_monthly_deposit(double amount) {
        balance += amount;
    }

    void calculate_interest() {
        double monthly_rate = annual_rate / 12.0;
        balance += balance * monthly_rate;
    }

    double get_final_amount(double monthly_deposit) {
        for (int i = 0; i < months; i++) {
            add_monthly_deposit(monthly_deposit);
            calculate_interest();
        }
        return balance;
    }
};

int main() {
    SavingsAccount account("홍길동", 0.12, 3);

    double monthly_deposit = 1000000;
    double final_amount = account.get_final_amount(monthly_deposit);

    cout << "최종 잔액: " << final_amount << "원" << endl;
    cout << "단순 합산 금액: " << monthly_deposit * 3 << "원" << endl;

    if (final_amount > monthly_deposit * 3) {
        cout << "복리 이자가 적용되어 더 큽니다" << endl;
    } else {
        cout << "단순 합산과 동일하거나 작습니다" << endl;
    }

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: