I propose to formally implement setters and getters for all sizes.
A method that calculates interest and a method that posts interest to the account.
class bank_account {
public:
bank_account();
void SetAccountNo(int account_no);
int GetAccountNo();
void deposit(float amount); void withdraw(float amount); void setInterestRate(float interest_rate);
float getInterestRate();
float getinterest(); float getBalance();
void calcInterest(int years);
private:
int dm_account_no;
float dm_balance;
float dm_interest_rate;
float dm_interest_earned;
};
bank_account::bank_account()
{
dm_account_no = 0;
dm_balance = 0.0;
dm_interest_rate = 0.0;
dm_interest_earned = 0.0;
}
void bank_account::calcInterest(int years)
{
for (int i = 0; i < years; i++) {
dm_interest_earned += getinterest();
dm_balance += getinterest();
}
}
int account_no[4] = { 80045001,80045002,80045003,80045004 };
float opening_balance[4] = { 100,200,300,400 };
float interest_rate[4] = { 0.01f,0.02f,0.03f,0.04f };
const int N = 4;
int main()
{
std::vector <bank_account>account(N);
for (int i = 0; i < N; i++) {
account[i].SetAccountNo(account_no[i]);
account[i].deposit(opening_balance[i]); account[i].setInterestRate(interest_rate[i]);
}
for (int i = 0; i < N; i++) {
account[i].calcInterest(5);
}
Notice:
It's usually not a good idea to store money in a float variable. A long int that stores cents would be worth considering.