Question: Create a menu that allows you to select the account type and then gives you option: 1) deposit 2) withdraw 3) check balance 4) monthly
Create a menu that allows you to select the account type and then gives you option:
1) deposit 2) withdraw 3) check balance 4) monthly processing 5) exit
Use BankAccount pointers and polymorphism.
#include
using namespace std;
class SavingAccount : public BankAccount { private: bool status; public: SavingAccount(double balace, double rate): BankAccount(balace,rate) {
}
bool checkStatus() { if (BankAccount::balance < 25.0) return false;
else return true; }
void withdraw(double amount) { if (checkStatus()) { BankAccount::withdraw(amount); } }
void deposit(double amount) { if (checkStatus() == false) { if (BankAccount::balance + amount > 25) status = true; }
BankAccount::deposit(amount); }
void monthlyProc() { if (BankAccount::noOfWithdrawl > 4) { BankAccount::monthlyServiceCharge += 1; BankAccount::balance -= 1;
if (BankAccount::balance < 25) status = false; } } };
class CheckingAccount :public BankAccount { public: CheckingAccount(double balace, double rate) : BankAccount(balace, rate) {
}
void withdraw(double amount) { if (balance - amount < 0) { monthlyServiceCharge += 15; balance -= 15; }
else BankAccount::withdraw(amount); }
void monthlyProc() { monthlyServiceCharge += 5; monthlyServiceCharge += 0.10*noOfWithdrawl; } };
int main() { BankAccount *saving = new SavingAccount(100,15); cout << "please enter amount to deposit in saving account: ";
double depositAmount, withdrawAmount; cin >> depositAmount; saving->deposit(depositAmount);
double monthStartBalance = depositAmount; cout << "please enter amount to withdraw from saving account: "; cin >> withdrawAmount; saving->withdraw(withdrawAmount);
cout << "Month start balance: " << monthStartBalance << endl; cout << "Total No of depost: " << saving->getNoOfDeposit() << endl; cout << "Total no of withdrawl: " << saving->getNoOfWithdrawl() << endl; cout << "Monthly service charge: " << saving->getMonthleServiceCharge() << endl; cout << "Month Ending balance: " << saving->getbalance() << endl;
//Checkingaccount BankAccount *checking = new CheckingAccount(500, 10); cout << "please enter amount to deposit in checking account: "; cin >> depositAmount; checking->deposit(depositAmount);
monthStartBalance = depositAmount; cout << "please enter amount to withdraw from checking account: "; cin >> withdrawAmount; checking->withdraw(withdrawAmount); cout << "Month start balance: " << monthStartBalance << endl; cout << "Total No of depost: " << checking->getNoOfDeposit() << endl; cout << "Total no of withdrawl: " << checking->getNoOfWithdrawl() << endl; cout << "Monthly service charge: " << checking->getMonthleServiceCharge() << endl; cout << "Month Ending balance: " << checking->getbalance() << endl;
getchar(); return 0; }
//BankAccount.h
#pragma once #ifndef BANKACCOUNT_H #define BANKACCOUNT_H
class BankAccount { protected: double balance; int noOfDeposit; int noOfWithdrawl; double AnnualInterestRate; double monthlyServiceCharge; public: BankAccount(double bal, double interestRate) { balance = bal; AnnualInterestRate = interestRate; noOfDeposit = 0; noOfWithdrawl = 0; monthlyServiceCharge = 0; } virtual void deposit(double amount) { balance += amount; noOfDeposit++; }
virtual void withdraw(double amount) { balance -= amount; noOfWithdrawl++; }
virtual void calcint() { double MonthlyInterestRate = (AnnualInterestRate / 12); double MonthlyInterest = balance * MonthlyInterestRate; balance = balance + MonthlyInterest; }
virtual void monthlyProc() { balance -= monthlyServiceCharge; calcint(); noOfDeposit = 0; noOfWithdrawl = 0; monthlyServiceCharge = 0; }
double getbalance() { return balance; }
int getNoOfDeposit() { return noOfDeposit; }
int getNoOfWithdrawl() { return noOfWithdrawl; }
double getMonthleServiceCharge() { return monthlyServiceCharge; } };
#endif
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
