C++ Using Classes to Create Banking Accounts

In my C++ class, I have given an assignment to create a set of classes to create multiple types of bank accounts. I decided to make an example of such a program that uses a base class and subclasses for checking, mortgage, savings, etc. The following video works correctly until the very end, where an exception happens when trying to exit the program. I did add a “delete accountNum” at the last minute and I need to see if that caused a problem since I have multiple instances of the AccountNumber class, one for each BankAccount class. I will look at this, but the video is fine until the very end.

Main test program Requirements

These are the main requirements for testing each of the account types. At the end of this description I will post the file I am using to test my code.

  1. For each account type, you should be able to print the current balance and account number. Perhaps having these routines/methods/functions in each class may be helpful.
  2. For a checking account, you should be able to deposit an initial amount, deposit funds, withdraw funds, and query current balance. It should flag when you go below a zero balance.
  3. Have a checking account (inherited from the previous class) that pays interest.
  4. Create a savings account that has the same features as the interest baring checking account but limits withdrawals to three per month.
  5. Have a CD that pays 5% compounded yearly, but charges a fee if the funds cannot be withdrawn more than twice per year.
  6. Have a mortgage account (see the video above for my implementation). It should calculate a monthly payment, given an initial loan, loan percentage, and the length of the loan in years. Be able to make a monthly payment and print the balance after each loan payment. Perhaps you can keep track of the months by each mortgage payment.

Sample of my Main Program

The following is the sample of my main program to test out my code:

/* Main file
 * Wayne Cook
 * 10 February 2021
 *  Test program for bank accounts. In this version, I am testing checking accounts
 *  and a mortgage. You should also have a CD account that earns interest
 *  each month. Also have a subclass to checking that earns interest each month.

#include "CheckingAccount.h"
#include "Mortgage.h"

int main() {
	CheckingAccount chAc[2];
	cout << "Before mortgage created." << endl;
	cout << "Checking account 1 number is: " << chAc[0].getAccountNumber() << endl;
	cout << "Checking account 2 number is: " << chAc[1].getAccountNumber() << endl;
	Mortgage mortgage;
	cout << "After mortgage created." << endl;
	cout << "Checking account 1 number is: " << chAc[0].getAccountNumber() << endl;
	cout << "Checking account 2 number is: " << chAc[1].getAccountNumber() << endl;
	cout << "Current Balance is: " << chAc[0].getBalance() <<
		" in Account " << chAc[0].getAccountNumber() << endl;
	cout << "Current Balance is: " << chAc[1].getBalance() <<
		" in Account " << chAc[1].getAccountNumber() << endl;
	cout << "Initial Mortgage balance is: " << mortgage.getBalance() <<
		" with monthly payment " <<	mortgage.getMonthlyPayment() <<
		" in account " << mortgage.getAccountNumber() << endl;
	cout << "Mortgage balance after one payment is: " <<
		mortgage.getBalance() << endl;

I would enjoy hearing from you.

This site uses Akismet to reduce spam. Learn how your comment data is processed.