#include <iostream>
#include <string>
using namespace std;

class Account {
protected:
    string accountNumber;
    double balance;

public:
    Account(string acc = "", double bal = 0) {
        accountNumber = acc;
        balance = bal;
    }

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

    void withdraw(double amount){
            balance -= amount;
    }

    double getBalance() {
        return balance;
    }
};

class SavingsAccount : public Account {
private:
    double interestRate;

public:
    SavingsAccount(string acc, double bal, double rate)
        : Account(acc, bal), interestRate(rate) {}

    void addInterest() {
        double interest = balance * (interestRate / 100);
        balance += interest;
    }

    void showInfo() {
        cout <<"잔액: " << balance<< endl;
    }
};

int main() {
    string acc;
    double bal, rate;

    cin >> acc;
    cin >> bal;
    cin >> rate;

    SavingsAccount myAcc(acc, bal, rate);

    cout << "\n[이자 적용 전]" << endl;
    myAcc.showInfo();

    myAcc.addInterest();

    cout << "\n[이자 적용 후]" << endl;
    myAcc.showInfo();

    return 0;
}

Embed on website

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