Question

25. Savings Account Balance Write a program that calculates the balance of a savings account at the end of a three-month feri
i need this to be in OOP using C++
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

using namespace std;

class Saving
{
   double deposit;
   double withdraw;
   double interest;
   double rate;
   double finalAmount;
  
   public:
       Saving()
       {
           this->deposit=0;
           this->withdraw=0;
           this->interest=0;
           this->finalAmount=0;
           this->rate=0;
       }
      
       void setDeposit(double deposit)
       {
           this->deposit+=deposit;
           this->finalAmount+=deposit;
       }
       double getDeposit()
       {
           return this->deposit;
       }
       void setWithdraw(double withdraw)
       {
           this->withdraw+=withdraw;
           this->finalAmount-=withdraw;
       }
       double getWithdraw()
       {
           return this->withdraw;
       }
       double setInterest(double interest)
       {
           this->interest+=interest;
       }
       double getInterest()
       {
           return this->interest;
       }
       void setRate(double rate)
       {
           this->rate=rate/12;
       }
       double getRate()
       {
           return this->rate;
       }
       double getTotalAmount()
       {
           return this->finalAmount;
       }
       void calculateInterest()
       {
           double amount=finalAmount*(rate);
          
           this->interest+=amount;
           this->finalAmount+=amount;
       }
      
};

int main()
{
   double rate,deposit,withdraw;
   Saving saving;
  
   label:
   cout<<"Enter interest rate:";
   cin>>rate;
  
   if(rate<0)
   {
       cout<<"Interest rate cannot be negative.";
   }
   saving.setRate(rate);
  
   cout<<"Current Balanace is:"<<((saving.getDeposit()-saving.getWithdraw())+saving.getInterest());
   cout<<endl<<"--------------------------------------------"<<endl;
  
   for(int i=1;i<=3;)
   {
       cout<<"Enter following for month "<<i<<":"<<endl;
      
       cout<<"Enter Deposited Amount:";
       cin>>deposit;
      
       if(deposit<0)
       {
           cout<<"Deposit amount cannot be negative."<<endl;
           continue;
          
       }
      
       cout<<"Enter Withrawal Amount:";
       cin>>withdraw;
  
       if(withdraw<0)
       {
           cout<<"Withdraw amount cannot be negative."<<endl;
       }
       else if((deposit+saving.getTotalAmount())>withdraw)
       {
           saving.setDeposit(deposit);
           saving.setWithdraw(withdraw);
           saving.calculateInterest();
           i++;
       }
       else
       {
           cout<<"Cannot withdraw more than deposited amount."<<endl;
       }
      
   }
   cout<<"Total Deposit:"<<saving.getDeposit()<<endl;
   cout<<"Total Withdraw:"<<saving.getWithdraw()<<endl;
   cout<<"Total Interest:"<<saving.getInterest()<<endl;
   cout<<"Total Balance:"<<saving.getTotalAmount()<<endl;
}

- O X C:\Users\CodeManiac\Documents\Saving.exe Current Balanace is:0 Enter following for month 1: Enter Deposited Amount:-100

Add a comment
Know the answer?
Add Answer to:
i need this to be in OOP using C++ 25. Savings Account Balance Write a program...
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
  • C++ 18. Savings Account Balance Write a program that calculates the balance of a savings account...

    C++ 18. Savings Account Balance Write a program that calculates the balance of a savings account at the end of a three month period. It should ask the user for the starting balance and the annual interest rate. A loop should then iterate once for every month in the period, performing the following A) Ask the user for the total amount deposited into the account during that month. Do not accept negative numbers. This amount should be added to the...

  • 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,...

  • Write in C++ using emacs. Write a program that calculates the ending balance of several savings...

    Write in C++ using emacs. Write a program that calculates the ending balance of several savings accounts. The program reads information about different customers’ accounts from an input file, “accounts.txt”. Each row in the file contains account information for one customer. This includes: the account number, account type (premium, choice, or basic account), starting balance, total amount deposited, and total amount withdrawn. Your program should: - open the file and check for successful open, - then calculate the ending balance...

  • Write a program to produce a table that shows the balance of a bank account after...

    Write a program to produce a table that shows the balance of a bank account after each month, assuming that interest is compounded monthly and no additional money is added or withdrawn from the account. Consider this example to understand how this calculation can be done with a loop. Suppose you put $10,000 into an account with an annual percentage rate (APR) of 5.0%. After one month, the account would receive an interest credit of 10000 * 5.0 / 1200....

  • Write a program that uses nested loops to collect data and calculate the average rainfall over...

    Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should prompt the user for the number of years. Be sure to ask for each months average rainfall for each year. The outer loop will iterate once for each year while the inner loop will iterate 12 times(one time per month) prompting for the months average rainfall on each iteration. Display the number of months, the total inches...

  • Hello I need C++ Code For the Following: Write a function declaration for a function that...

    Hello I need C++ Code For the Following: Write a function declaration for a function that computes interest on a credit card account balance. The function takes arguments for the initial balance, the monthly interest rate, and the number of months for which interest must be paid. The value returned is the interest due. Do not forget to compound the interest—that is, to charge interest on the interest due. The interest due is added into the balance due, and the...

  • 5. Create a java application that uses nested loops to collect data and calculate the average...

    5. Create a java application that uses nested loops to collect data and calculate the average rainfall over a peniod of years First the program should ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month, the program should display the number of months, the total...

  • Suppose you have a certain amount of money in a savings account that earns compound monthly...

    Suppose you have a certain amount of money in a savings account that earns compound monthly interest, and you want to calculate the amount that you will have after a specific number of months. The formula is as follows: f = p * (1 + i)^t • f is the future value of the account after the specified time period. • p is the present value of the account. • i is the monthly interest rate. • t is the...

  • JAVA PLEASE! Suppose you save $100 each month into a savings account with the annual interest...

    JAVA PLEASE! Suppose you save $100 each month into a savings account with the annual interest rate 5%. So, the monthly interest rate is 0.05/12 = 0.00417. After the first month, the value in the account becomes 100 * (1 + 0.00417) = 100.417 After the second month, the value in the account becomes (100 + 100.417) * (1 + 0.00417) = 201.252 After the third month, the value in the account becomes (100 + 201.252) * (1 + 0.00417)...

  • Write a program in C++ that lets the user enter the total rainfall for each of...

    Write a program in C++ that lets the user enter the total rainfall for each of 12 months into an array of doubles. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Input validation: Do not accept negative numbers for monthly rainfall figures.

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
ADVERTISEMENT