Question
Create a SavingsAccount class. Use a static data member annual BonusRate to store the annual bonus rate for each of the savers (i.e. objects). The class contains a private data member savingsBalance indicating the amount the saver currently has on deposit. Provide member function calculateMonthlyBonus that calculates the monthly bonus by multiplying the savings Balance by annualBonusRate divided by 12; this bonus should be added to savings Balance. Provide a static member function modifyBonusRate that has a parameter and use it to set the static annualBonusRate to a new value. Write a driver program (containing main) to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver 2, with balances of $2000.00 and $3000.00, respectively. Set annualBonusRate to 3 percent only once. Then calculate the monthly bonus and print the new balance for object, saver 1. Will the annualBonusRate be same for all objects? Explain your answer.
Explanation / Answer
#include using namespace std; class SavingsAccount { public: SavingsAccount(){} SavingsAccount(int value); ~SavingsAccount(){} static float annualInterestRate; void calculateMonthlyInterest(); static void modifyIntererestRate(float value); float GetBalance() const { return savingsBalance; } private: // Each member of the class contains a private data member // savingsBalance indicating the amount the saver currently has // on deposit. float savingsBalance; }; // copy constructor to initialize the value at instantiation SavingsAccount::SavingsAccount(int value) { savingsBalance = value; } // Use a static data member annualInterestRate to store the annual interest // rate for each of the savers. float SavingsAccount::annualInterestRate = 0; // Provide member function calculateMonthlyInterest that calculates the // monthly interest by multiplying the savingsBalance by annualInterestRate // divided by 12 and then adds this interest to savingsBalance. void SavingsAccount::calculateMonthlyInterest() { savingsBalance += ((savingsBalance * annualInterestRate) / 12); } //Provide a static member function modifyIntererestRate that sets the // static annualInterestRate to a new value. void SavingsAccount::modifyIntererestRate(float value) { annualInterestRate = value; } int main() { // Instantiate two different objects of class SavingsAccount, saver1 // and saver2, with balances of $2000.00 and $3000.00, respectively. SavingsAccount saver1(2000.00); SavingsAccount saver2(3000.00); // Set the annualInterestRate to 3%. SavingsAccount::modifyIntererestRate(3); // Then calculate the monthly interest and print the new balances for // each of the savers. saver1.calculateMonthlyInterest(); cout