Create class SavingsAccount. Use a static class variable to store the annualInte
ID: 3631104 • Letter: C
Question
Create class SavingsAccount. Use a static class variable to store the annualInterestRate for all of the savers. Each object of the class contains a private instance variable savingsBalance indicating the amount the saver currently has on deposit. Provide method calculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12; this interest should be added to savingsBalance. Provide a static method modifyInterestRate that sets the annualInterestRate to a new value. Write a driver program to test class SavingsAccount. Instantiate two different savingsAccount objects, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively. Set annualInterestRate to 4%, then calculate the monthly interest and print the new balances for each of the savers. Then set the annualInterestRate to 5% and calculate the next month’s interest and print the new balances for each of the savers.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(); coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.