// BankAccountCheckingSaving.cpp : This file contains the 'main' function. Program execution begins and ends there.
// Chapter 15 [Gaddis], Programming Challenge 14: Bank Accounts
#include <iostream>
#include <cctype>
#include "SavingsAccount.h"
#include "CheckingAccount.h"
using namespace std;
// Function prototype
void dispatch(int, SavingsAccount &, CheckingAccount &);
int main()
{
SavingsAccount savings; // A Savings object
CheckingAccount checking; // A Checking object;
int choice; // To hold the user's menu choice
do // menu
{
cout << "\n\n******** BANK ACCOUNT MENU ********\n\n";
cout << "1. Savings Account Deposit\n";
cout << "2. Checking Account Deposit\n";
cout << "3. Savings Account Withdrawal\n";
cout << "4. Checking Account Withdrawal\n";
cout << "5. Update and Display Account Statistics\n";
cout << "6. Exit\n\n";
cout << "Your choice, please: (1-6) ";
cin >> choice;
// Validate the menu selection.
while (choice < 1 || choice > 6)
{
cout << "Enter a number from 1 through 6 please: ";
cin >> choice;
}
// Execute the user's choice.
dispatch(choice, savings, checking);
} while (choice != 6);
return 0;
}
//*********************************************
// dispatch menu *
// This function executes the choice made by *
// the user. *
//*********************************************
void dispatch(int choice, SavingsAccount &savings, CheckingAccount &checking)
{
switch (choice)
{
case 1:
savings.Deposits();
break;
case 2:
checking.Deposits();
break;
case 3:
savings.Withdraws();
break;
case 4:
checking.Withdraws();
break;
case 5:
cin.ignore();
savings.monthlyProc();
cout << "\nPress a key to continue... ";
cin.get();
checking.monthlyProc();
}
}
#ifndef AccountDetailsH
#define AccountDetailsH
#include <vector>
using namespace std;
class AccountDetails
{
public:
float numdeposit;
float numwithdraw;
float monthlyservicecharge;
int const AnnualinterestRate = 3.75;
float Deposits();
float Withdraws();
float Balance = 0;
float getcalcnt();
void monthlyProc();
};
#endif
#ifndef AccountDetailsCPP
#define AccountDetailsCPP
#include "AccountDetails.h"
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
void AccountDetails::monthlyProc()
{
this->numwithdraw = numwithdraw;
this->numdeposit = numdeposit;
this->monthlyservicecharge = monthlyservicecharge;
getcalcnt();
Balance = Balance - monthlyservicecharge;
}
float AccountDetails::Withdraws()
{
float Withdraw;
int amount;
vector<int> userWithdraw;
cout << "Enter amount to withdraw: ";
cin >> amount;
userWithdraw.push_back(amount);
numwithdraw = userWithdraw.size();
cout << "You have made " << userWithdraw.size() << " Withdraws so far." << endl;
Withdraw = accumulate(userWithdraw.rbegin(), userWithdraw.rend(), 0); // adds all deposits together.
Balance = Balance - Withdraw;
return Balance;
}
float AccountDetails::getcalcnt()
{
float MonthlyinterestRate = 0;
MonthlyinterestRate = MonthlyinterestRate + (AnnualinterestRate / 12);
float MonthlyInterest = MonthlyinterestRate * Balance;
Balance = Balance + MonthlyInterest;
return Balance;
}
float AccountDetails::Deposits()
{
float Deposit;
int amount;
vector<int> userDeposit;
cout << "Please enter the amount" << endl;
cin >> amount;
userDeposit.push_back(amount);
numdeposit = userDeposit.size();
cout << "You have made " << userDeposit.size() << " deposits so far." << endl;
Deposit = accumulate(userDeposit.rbegin(), userDeposit.rend(), 0); // adds all deposits together.
Balance = Balance + Deposit;
return Balance;
}
#endif
#ifndef CheckingAccountH
#define CheckingAccountH
#include "AccountDetails.h"
class CheckingAccount : public AccountDetails
{
public:
float checkwithdraw();
};
#endif
#ifndef SavingsAccountH
#define SavingsaccountH
#include "AccountDetails.h"
class SavingsAccount : public AccountDetails
{
public:
float Activewithdraw();
float Activedeposit();
void monthlyProc();
};
#endif
#ifndef CheckingAccountCPP
#define CheckingAccountCPP
#include "AccountDetails.h"
#include "CheckingAccount.h"
#include <iostream>
using namespace std;
float CheckingAccount::checkwithdraw()
{
AccountDetails::Withdraws();
if (Balance < 0)
{
Balance = Balance - 15;
cout << "Your balance is now negative";
cout << "It is " << Balance;
}
return Balance;
}
#endif
#ifndef SAVINGSACCOUNTCPP
#define SAVINGSACCOUNTCPP
#include "AccountDetails.h"
#include "SavingsAccount.h"
#include <iostream>
using namespace std;
float SavingsAccount::Activewithdraw()
{
Withdraws();
if (Balance < 25)
{
cout << "Your Balance is less than $25" << endl;
cout << "Your account is inactive" << endl;
cout << "To active your account raise it to at least $25" << endl;
Withdraws();
}
return Balance;
}
float SavingsAccount::Activedeposit()
{
Deposits();
if (Balance > 25)
{
cout << "Your account is active" << endl;
Deposits();
}
return Balance;
}
void SavingsAccount::monthlyProc()
{
AccountDetails::monthlyProc();
Withdraws();
if (numwithdraw > 4)
{
monthlyservicecharge = monthlyservicecharge - (numwithdraw - 4);
if (Balance < 25)
{
Activewithdraw();
}
}
}
#endif