Question

Define a class SavingsAccount with following characteristics. Use a static variable annualInterestRate of type float to...

Define a class SavingsAccount with following characteristics.

  • Use a static variable annualInterestRate of type float to store the annual interest rate for all account holders.
  • Private data member savingsBalance of type float indicating the amount the saver currently has on deposit.
  • Method calculateMonthlyInterest to calculate the monthly interest as (savingsBalance * annualInterestRate / 12). After calculation, the interest should be added to savingsBalance.
  • Static method modifyInterestRate to set annualInterestRate.
  • Parameterized constructor with savingsBalance as an argument to set the value of that instance.

Input
   4
   2000.00
   5

   Where,

  • First line represents initial annual Interest Rate.
  • Second line represents initial savingsBalance of the account.
  • Third line represents annual Interest Rate after one month.

Output
   2666.6667
   3777.7778

   Where,

  • First line represents the balance account after one month.
  • Second line represents the balance of the account after two months.

#include <iostream>
using namespace std;

int main()
{
//Write your code here
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;

class SavingsAccount
{
private:
   float savingsBalance;
public:
   static float annualInterestRate;
   // default constructor sets balance=0
   SavingsAccount(){
       savingsBalance = 0;
   }
   // parameterize constructor to set values
   SavingsAccount(int newVal){
       savingsBalance = newVal;
   }
   // accessor function of saving balance
   float getSavingBalance() {
       return savingsBalance;
   }
   // mutator function of saving balance
   void setSavingBalance(float newVal) {
       this->savingsBalance = newVal;
   }
// this function calculates monthly interest by using formula (savingsBalance * annualInterestRate / 12)
   void calculateMonthlyInterest (){
       savingsBalance = savingsBalance + ((savingsBalance * annualInterestRate ) / 12);
   }
   // this function sets new interest rate
   void modifyInterestRate (float newVal){
       annualInterestRate = newVal;
   }
};
float SavingsAccount::annualInterestRate = 0; //intializing static varaible equal to

int main()
{
   float savingsBalance;
   float annualInterest;
   float modifiedIntrest;
   cout << "Enter saving balance: ";
   cin >> savingsBalance;
   cout << "Enter annual interest: ";
   cin >> annualInterest;
   // object decalred wiht parameterized constructor
   SavingsAccount obj(savingsBalance);
   // annual interest set
   obj.modifyInterestRate (annualInterest);
   obj.calculateMonthlyInterest();
   cout << "Enter modified annual interest: ";
   cin >> modifiedIntrest;
   cout << "Savings Balance: " << obj.getSavingBalance() << endl;
   obj.modifyInterestRate(modifiedIntrest);
   obj.calculateMonthlyInterest();
   cout << "Savings Balance: $" << obj.getSavingBalance() << endl;
   return 0;
}

OUTPUT:

CODE SNIP:

IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW
PLEASE GIVE A THUMBS UP

Add a comment
Know the answer?
Add Answer to:
Define a class SavingsAccount with following characteristics. Use a static variable annualInterestRate of type float to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a .java file that has class SavingsAccount. Use a static variable annualInterestRate to store the...

    Create a .java file that has class SavingsAccount. Use a static variable annualInterestRate to store the annual interest rate for all account holders. 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 setInterestRate that sets the annualInterestRate to a new value....

  • JAVA Create a class called SavingsAccount. The class should have a static variable named, annualInterestRate, to...

    JAVA Create a class called SavingsAccount. The class should have a static variable named, annualInterestRate, to store the annual interest rate for all account holders. Each object of the class should contain a private instance variable named, savingsBalance, indicating the amount the saver currently has on deposit. Write methods to perform the following: calculateMonthlyInterest – calculates the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12. This interest should be added to the balance. depositAmount – allows the...

  • Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to...

    Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to store the annual interest rate for all account holders.  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 static method setAnnualInterestRate to set the annualInterestRate to a new value....

  • Application should be in C# programming language Create a class called SavingsAccount.  ...

    Application should be in C# programming language Create a class called SavingsAccount.  Use a static variable called annualInterestRate to store the annual interest rate for all account holders.  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 static method setAnnualInterestRate to set the...

  • C# How to Program: 10.5 Savings account class

    Create the class savings account. Use the static variable annualInterestRate to store the annual interest rate for all account holders. Each object of the classcontains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate themonthly interest by multiplying the savingsBalance by annualInterestRate divided by 12, this interest should be added to savingsBlance, Provide static methodModifyInterestRate to set the annualInterestRate to a new value. Write an application to test class SavingsAccount....

  • Using C++ Please make sure you comment each section of the program so I can better...

    Using C++ Please make sure you comment each section of the program so I can better understand it. Thank you! Assignment Content You are now working for a bank, and one of your first projects consists of developing an application to manage savings accounts. Create a C++ program that does the following: Creates a SavingsAccount class Uses a static data member, annualInterestRate, to store the annual interest rate for each of the savers Ensures each member of the class contains...

  • a) Create saving account Class. Use a static data member annualBonusRate to store the annual bonus...

    a) Create saving account Class. Use a static data member annualBonusRate to store the annual bonus rate for each of the savers (objects) b) The class contains a private data member savingBalance indicating the amount the saver currently has on deposit. c) Provide member function calculate MonthlyBonus that calculates the monthly bonus by multiplying the savingBalance by annualBonusRate divided by 12; this bonus should be addad to savingBalance. d) Provide a static member function modifyBunusRate that has a parameter and...

  • Now create another class named SavingsAccount. This should be a subclass of BankAccount. A SavingsAccount should...

    Now create another class named SavingsAccount. This should be a subclass of BankAccount. A SavingsAccount should have an interest rate that is specified in its constructor. Furthermore, there should be a method, addInterest, that deposits interest into account, based on the account balance and interest rate. Create another subclass of BankAccount named CheckingAccount. A CheckingAccount should keep track of the number of transactions made (deposits and withdrawals). Name this field transactionCount. Also, the set fee for transactions is three dollars,...

  • solve this JAVA problem in NETBEANS Problem #12 in page 400 of your text (6th edition): SavingsAccount Class. Design a SavingsAccount class that stores a savings account's annual interest rate...

    solve this JAVA problem in NETBEANS Problem #12 in page 400 of your text (6th edition): SavingsAccount Class. Design a SavingsAccount class that stores a savings account's annual interest rate and balance. The class constructor should accept the amount of the savings account's starting balance. The class should also have methods for subtracting the amount of a withdrawal, adding the amount of a deposit, and adding the amount of monthly twelve. To add the monthly interest rate to the balance,...

  • /*Design a class BankAccount that has the following properties: * Account Number (should be static and increased every...

    /*Design a class BankAccount that has the following properties: * Account Number (should be static and increased every time an account is created. * An array of holders max 5 and a holder is a Person object * A int to rember how many holders * Balance (float) * Date opened * interest rate * Constructors * addHolder will add one more Person as a holder, if you reach 5 don't add. * Setters getters * method payInterest that add...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT