Bank Account Inheritance Help

My homework assignment for school. Just wondering if anyone with some expertise could look over it. The question is:

LAB 5 - BANK ACCOUNTS

For this lab you will complete the implementation of an application that manages bank accounts.

There is a base Account class that manages the basic operations of a bank account, such as deposits and withdrawals. The specifics of a checking account and savings account should be managed by the more specialized classes Checking and Savings.

On both types of accounts you should not let the balance drop below zero, so this should be checked before making a withdrawal.

When running the monthly statement, the savings account should add the interest earned to its balance, and the checking account should subtract the charges, if any, from its balance.

The default interest rate for a savings account is 1% as specified in the default value of the constructor's parameter. That means if you don't specify a different value when creating an object, that should be the rate used. I will test your class to see if it works with the default value and with different interest rates values as well.

Similarly, a checking account object can be created with two default parameters: one that specifies a 10-cent charge per withdrawal, and one that sets the number of free withdrawals to 5. In that case, if there is up to 5 withdrawals from the account in a particular month, there are no charges. For more than 5 withdrawals, there is a 10-cent charge per withdrawal. For example, if there are 7 withdrawals, there is a 20-cent charge. Again, those parameters can be changed when the object is created.

The monthlyStatement should reset the value for the number of withdrawals, so it starts fresh the following month.

It is important that you use what is already implemented in the base BankAccount class by calling its methods. Do not replicate what is already implemented in BankAccount, since reuse of code is one of the main purposes of object oriented programming. The more specialized class is supposed to extend the base class. For example, the Checking::deposit member function should call the BankAccount::deposit to do the basic updates and just add the behavior that is specific to checking. Same for Savings and any other member function that you override.

You need to write a main function to test your classes, but you don't have to turn it in. I will use my own, so it is very important that you don't change the interface, or the class specification that I'm providing. Only turn in Checking.cpp and Savings.cpp with the subclasses implementations.

The following is provided:

BankAccount.h: The base class implementation. Do not change these files.

Checking.h: The specification of your checking account class, which is a subclass of BankAccount. Do not change this file. You will implement the Checking.cpp

Savings.h: The specification of your savings account class, which is a subclass of BankAccount. Do not change this file. You will implement the Savings.cpp

Turn in your implementation of Checking.cpp and Savings.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
 #ifndef BANKACCOUNT_H_
#define BANKACCOUNT_H_

#include <iostream>

class BankAccount {
protected:
	double balance;
public:
	BankAccount(double startingBalance)
		{ balance = startingBalance; }

	virtual ~BankAccount() {}

	virtual void deposit(double amt)
		{ balance += amt; }

	virtual void withdraw(double amt)
		{ balance -= amt; }

	virtual void printMonthlyStatement() = 0; // pure virtual function
};

#endif /* BANKACCOUNT_H_ */

#ifndef CHECKING_H_
#define CHECKING_H_

#include "BankAccount.h"

class Checking : public BankAccount{
private:
	double charges;
	int maxW; // maximum of free withdrawals per month
	int withdrawals; // number of withdrawals this month
	void applyCharges(); // calculates the monthly charges and subtracts it from the balance

public:
	// default: a charge of $0.1 applies after 5 withdrawals per month
	Checking(double amt, int maxW = 5, double charges = 0.1);
	virtual ~Checking();
	void deposit(double amt);  // calls deposit from base class
	void withdraw(double amt); // checks if enough funds before calling withdraw from base class
	void printMonthlyStatement(); // prints monthly statement after calculating the charges to update the balance
};

#endif /* CHECKING_H_ */

#ifndef SAVINGS_H_
#define SAVINGS_H_

#include "BankAccount.h"

class Savings : public BankAccount {
private:
	double interestRate;
	void applyInterest();  // calculates the monthly interest and adds it to the balance

public:
    Savings(double amt, double intRate = 0.01);
	virtual ~Savings();
	void deposit(double amt);    // calls deposit from base class
	void withdraw(double amt);   // checks if enough funds before calling withdraw from base class
	void printMonthlyStatement(); // prints monthly statement after calculating the interest to update the balance
};

#endif /* SAVINGS_H_ */

#include "Checking.h"

using namespace std;


Checking::Checking(double amt, int maxW, double charges): BankAccount(amt)
{
    this->maxW = maxW;
    this->charges = charges;
    withdrawals = 0;
}
Checking:: ~Checking()
{
    
}
void Checking:: deposit(double amt)// calls deposit from base class
{
    BankAccount::deposit(amt);
}
void Checking:: withdraw(double amt) // checks if enough funds before calling withdraw from base class
{
    if(amt < balance)
    {
        BankAccount::withdraw(amt);
        withdrawals++;
    }
    else
    {
        cout << "Insuffient funds to complete this transaction" << endl;
    }
}
void Checking:: applyCharges()
{
    if(withdrawals > maxW)
    {
        balance -= ((withdrawals - maxW) * charges);
    }
    
}
void Checking::printMonthlyStatement()
{
    applyCharges();
    
    cout << "Your Balance is: " << balance << endl;
    cout << "You made " << withdrawals << " total withdrawals" << endl;
    withdrawals = 0;
    
}// prints monthly statement after calculating the charges to update the balance

#include "Savings.h"

using namespace std;


Savings::Savings(double amt, double intRate) :BankAccount(amt)
{
    interestRate = intRate;
}

Savings::~Savings()
{
    
}
void Savings::deposit(double amt)   // calls deposit from base class
{
    BankAccount::deposit(amt);
}
void Savings::withdraw(double amt)// checks if enough funds before calling withdraw from base class
{
    if(amt < balance)
    {
        BankAccount::withdraw(amt);
    }
    else
    {
        cout << "Insuffient funds to complete this transaction" << endl;
    }
}

void Savings:: applyInterest()
{
    balance = (balance *= interestRate);
}
Topic archived. No new replies allowed.