Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Implement a class Account. An account has a balance, functions to add and wi

ID: 3746630 • Letter: C

Question

C++

Implement a class Account. An account has a balance, functions to add and withdraw money, and a function to query the current balance. Charge $20 penalty if an attempt is made to withdraw more money than available in the account. Enhance the Account class to compute the interest on the current balance. An account has initial balance of $10,000.00, and 6% percent annual interest is compounded monthly until the investement is double.
Write a main function to determine the number of months to double the initial investment. Create a menu to allow the user to enter the initial investement and the annual interest rate.

Implement a class Bank. This bank has two objects, checking and savings of type Account that was developed above. Implement four member functions:

   deposit(double amount, string account)
   withdraw(double amount, string account)
     transfer(double amount, string account)
   print_balance()

Here is the account string is "S" or " C". For the deposit or withdrawl, it indicates which account is affected. For a transfer it indicates the account from which the money the money is taken; the money is automatically transfer to the other account.

Explanation / Answer

#include <iostream>
#include <cmath>
using namespace std;

class Bank
{

public:
double savingAmount, checkingAmount, rate;
Bank()
{
savingAmount = 10000;
checkingAmount = 10000;
rate = 6;
}
Bank(double a, double r)
{
savingAmount = a;
rate = r;
}

double finding_time_to_double_Amt() // this function calculate months for doubling the initial amount
{

double months = savingAmount * rate / 1200;
months = savingAmount / months;
return months;
}

void deposit(double a, string account)
{
if (a < 0)
{
return;
}
if (account == "S")
savingAmount += a;
if (account == "C")
checkingAmount += a;
}

void withdraw(double a, string account)
{
if (savingAmount - a < 0)
{
cout << "$20 penalty charged because you withdraw more money than available in the account ";
if (account == "S")
savingAmount -= 20;
if (account == "C")
checkingAmount -= 20;
}
if (account == "S")
savingAmount -= a;
if (account == "C")
checkingAmount -= a;
}

void print_balances()
{
cout << "Saving Amount :$ " << savingAmount << " Checking Amount is :$ " << checkingAmount << endl;
}
void transfer(double amount, string account)
{

if (account == "C")
{
checkingAmount -= amount;
savingAmount += amount;
}

if (account == "S")
{
savingAmount -= amount;
checkingAmount += amount;
}
}
};

int main()
{
Bank Account;
double balance, rate;

cout << "Enter initial balance: $";
cin >> balance;
cout << "Enter annual interest rate: ";
cin >> rate;
Bank my_account(balance, rate); // Set up my account

cout << "Inital bank balances: ";
Account.print_balances(); /* set up empty accounts */

cout << "Adding some money 1000 to saving and 2000 to checking accounts: ";
Account.deposit(1000, "S"); /* deposit $1000 to savings */
Account.deposit(2000, "C"); /* deposit $2000 to checking */
Account.print_balances();
cout << "Taking out $1500 from checking,and moving $200 from";
cout << " savings to checking. ";
Account.withdraw(1500, "C"); /* withdraw $1500 from checking */
Account.transfer(200, "S"); // transfer $200 from savings
Account.print_balances();

cout << "Trying to transfer $900 from Checking to saving. ";
Account.transfer(900, "C");
Account.print_balances();

cout << "trying to transfer $900 from Savings to checking. ";
Account.transfer(900, "S");
Account.print_balances();

cout << "The time required to double the Initial amount is: " << my_account.finding_time_to_double_Amt() << " months." << endl;
}