Please Help! Bank Account Inheritance Assignment Problem

Hi, I was having problems with the following school assignment:

"Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int ad balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, print account information. Add appropriate constructors.
Every bank offers checking and saving accounts. Derive the class checkingAccount from the class bankAccount, which can be used to represent checking accounts. This class inherits members to store the account number and the balance from the base class. A customer with a checking account, typically, receives interest, maintains a minimum balance, and if the balance falls below the minimum balance, pays service charges. Add member variables to store this additional information. In addition to the operation inherited from the base class, this class should provide the following operations: set interest rate, set minimum balance, retrieve minimum balance, set service charges, retrieve service charges, post interest, verify if the balance is less than the minimum balance, write a check, withdraw (override the method of the base class), and print account information, Add appropriate constructors."

Its outputting the wrong amount for the balance, it is outputting 1669.97 as the balance when it should output 1719.97 as the balance amount. The following is the output I'm getting:

Account Number: 100584220
Account Balance: 1669.97
Minimum Balance: 350
Interest: 5
Service Charge: 15

Any help is appreciated. Thanks.

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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//bankAccount.h
#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H

#include <iostream>
using namespace std;

class bankAccount	//set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, print account information
{
public:
	bankAccount();				//sets account number and balance to zero as default;
	bankAccount(int, double, double, double);
	~bankAccount(){}
	void setAccountNum(int);	//sets account number
	int getAccountNum() const;			
	double getBalance() const;		
	void deposit(double);		//calculates deposit value
	void withdraw(double);		//calculates withdraw value
	void printAccountInfo() const;	//prints info

	void setBalance(double);
	

private:
	int accountNum;
	//double accountBalance;

protected:
	double accountBalance;
};

#endif


//bankAccount.cpp
#include "bankAccount.h"

bankAccount::bankAccount()
{
	accountNum = 0;
	accountBalance = 0;
};

bankAccount::bankAccount(int n, double b, double d, double w)
{
	setAccountNum(n);
	setBalance(b);
	deposit(d);
	withdraw(w);
};

void bankAccount::setAccountNum(int n)
{
	accountNum = n;
};

int bankAccount::getAccountNum() const
{
	return accountNum;
};

void bankAccount::setBalance(double b)
{
	accountBalance = b;
}
double bankAccount::getBalance() const
{
	return accountBalance;
};

void bankAccount::deposit(double d)
{
	if (d >= 0)
	{
		accountBalance += d;
	}
	else
	{
		cout << "The withdraw ammount is invalid. The withdraw ammount will be set to zero." << endl;
		d = 0;
		accountBalance += d;
	}
};		

void bankAccount::withdraw(double w)
{
	if (w >= 0)
	{
		accountBalance -= w;
	}
	else
	{
		cout << "The withdraw ammount is invalid. The withdraw ammount will be set to zero." << endl;
		w = 0;
		accountBalance -= w;
	}
};	

void bankAccount::printAccountInfo() const
{
	cout << "Account Number: " << accountNum << endl;
	cout << "Account Balance: " << accountBalance << endl;
};


//checkingAccount.h (derived class)
#ifndef CHECKINGACCOUNT_H
#define CHECKINGACCOUNT_H

#include <iostream>
#include "bankAccount.h"
using namespace std;

class checkingAccount : public bankAccount
{
public:
	checkingAccount();
	~checkingAccount(){}
	checkingAccount(int, double, double, double, double, double, double);
	void setInterest(double);
	void setminBalance(double);
	double getminBalance();
	void setServiceCharges(double);
	double getServiceCharges();
	void postInterest(); //verify if the balance is less than the minimum balance, write a check, withdraw (override the method of the base class), and print account information
	//void getInterest(double);
	void withdraw(double);
	void printAccountInfo() const;
	//void BalanceVerification();
	void CheckAmount(double);
private:
	double interest;
	double minBalance;
	double serviceCharges;
};

#endif



//checkingAccount.cpp (derived class definition)
#include "checkingAccount.h"

checkingAccount::checkingAccount() : bankAccount()
{
	interest = 0;
	minBalance = 0;
	serviceCharges = 0;
}
checkingAccount::checkingAccount(int n, double b, double d, double w, double i, double mb, double sc) : bankAccount(n, b, d, w)
{
	setInterest(i);
	setminBalance(mb);
	setServiceCharges(sc);
}
void checkingAccount::setInterest(double i)
{
	interest = i;
}
void checkingAccount::setminBalance(double mb)
{
	minBalance = mb;
}
double checkingAccount::getminBalance()
{
	return minBalance;
}
void checkingAccount::setServiceCharges(double sc)
{
	serviceCharges = sc;
}
double checkingAccount::getServiceCharges()
{
	return serviceCharges;
}
void checkingAccount::postInterest()
{
	accountBalance *= (1 + interest / 100);
	
} 
void checkingAccount::CheckAmount(double c)
{
	accountBalance -= c;
}
void checkingAccount::printAccountInfo() const
{
	cout << "Account Number: " << getAccountNum() << endl;
	cout << "Account Balance: " << getBalance() << endl;

	cout << "Minimum Balance: " << minBalance << endl;
	cout << "Interest: " << interest << endl;
	cout << "Service Charge: " << serviceCharges << endl;
	//cout << "Post Interest: " << 
};

void checkingAccount::withdraw(double w)
{
	accountBalance -= w;

	if ((accountBalance) < minBalance)
	{
		accountBalance -=serviceCharges;
	}
}


//main.cpp (testing)
#include "bankAccount.h"
#include "checkingAccount.h"

int main()
{
	checkingAccount Customer1;
	Customer1.setAccountNum(100584220);
	Customer1.setBalance(2500);
	Customer1.setServiceCharges(15);
	Customer1.setminBalance(350);
	Customer1.setInterest(5);
	
	Customer1.deposit(250);
	Customer1.withdraw(159.55);
	Customer1.CheckAmount(1000);
	Customer1.postInterest();
	Customer1.printAccountInfo();

	system("PAUSE");

	return 0;
}
Last edited on
Topic archived. No new replies allowed.