To start, you aren't really clear on class inheritance. For example, you have:
class bankAccount
{
private:
int accNumber;
float balance;
float interestRate;
public:
void deposit(float amount);
void withdraw(float amount);
void displayAccount(int, float);
void setupAccount(int, float, float);
bool matchAccount(int);
float getBalance();
};
...
class savingsAccount : public bankAccount
{
private:
int accNumber;
float balance;
float interestRate;
public:
void calculateInterest(float, float);
savingsAccount (int, float, float);
};
Members of a class which are safe to be inherited by derived classes should be "protected:" instead of "private:". The "private:" designation is probably rarely needed and is only relevant for portions of a parent class which, for whatever reason, should not or cannot be inherited by derived classes.
So if you make accNumber and balance "protected:" in bankAccount, you then get them for free in savingsAccount, which is part of the point.
Then your assignment specifically states:
"The generic bank account should contain an account number and balance data
members but no interest rate."
So I wonder why you have an interestRate member in your bankAccount class.
Your bankAccount class has no bankAccount() constructor. Instead it has a setupAccount() method which does the same thing. Resolve this by renaming setupAccount() to bankAccount(). Given that it shouldn't have an interest rate, do not provide or assign one in your constructor.
Then, also following the notion of inheritance, the constructor of your derived class should call the constructor of the base class, to avoid duplicating the same work (even though in your case, it's just trivial assignments):
savingsAccount::savingsAccount(int aN, float bal, float iRate):
bankAccount(aN, bal)
{
interestRate=iRate;
}
Also, you waste a lot of space respecifying method bodies which haven't changed. They're already declared as "public:" in the base class, so again, you get them for free. E.g.:
void bankAccount::deposit(float amount)
{
balance=balance+amount;
}
...
void savingsAccount::deposit(float amount)
{
balance=balance+amount;
}
although if you -do- need to override a method in a derived class, then you need to re-specify its prototype in the class definition!
So altogether, the only methods you need to specify for the derived class are (1) any -new- methods, such as the constructor, and in the case of the savingsAccount class, the calculateInterest() method, and (2) any methods that need to behave differently because of the specifics of the derived class -- in particular, re-read the part of the assignment that discusses the credit-card account and how the deposit() and withdrawal() methods should behave, you have them incorrect in your code.
Your bankAccount class specifies a displayAccount() method prototype which you haven't implemented.
You have a typo at your current line 237 which is probably causing you a bunch of headaches.
Finally (I'm not going to read any further this evening), your setup for the Customer class in general is broken.
First of all, you have default values in your constructor for almost every possible field, which in your case probably doesn't make sense: a customer will always have a name and address. Also, I'm reasonably sure that any parameters (to any method or function) which require a value must come first, and any that don't should follow, so that the compiler can figure out what values to assign to which parameters. You may also have to provide dummy parameter names in your prototype, if you're going to provide default values, e.g.
Customer(string, string, char, int acctNo=0, float bal=0.0);
Then you provide three implementations of your constructor, none of which takes the same parameters you specify in your one prototype. I think what you're trying to specify is something like:
Customer::Customer(string nme, string addr):
sAccnt(0, 0.0, 0.0), cAccnt(0, 0.0, 0.0), ccAccnt(0, 0.0, 0.0)
{
name = nme;
address = addr;
}
where you can use an accountNum of zero to indicate that the customer does not have an account of that type, until one is assigned. Otherwise, you will need other members (perhaps bools?) to indicate whether the customer has an account of each type.
The good news is: this means each account type needs an inherited or overridden setupAccount() to provide the actual info once you have it. Or you can use pointers to these account-types and instantiate them as needed:
class Customer
{
private:
string name;
string address;
savingsAccount *sAccnt;
checqueAccount *cAccnt;
creditAccount *ccAccmt;
public:
Customer(string, string);
void addSavingsAccount(int, float, float);
...
};
Customer::Customer(string nme, string addr):
sAccnt(NULL), cAccnt(NULL), ccAccnt(NULL)
{
name = nme;
address = addr;
}
void Customer::addSavingsAccount(int acctNo, float bal, float iRate)
{
sAccnt = new savingsAccount(acctNo, bal, iRate);
}
...
I can't recommend enough doing this step by step, putting things in separate files (and #include'ing what you need), and testing the parts as you go.
As far as having "no idea how to implement the other parts," get as far as you can, and get that muchworking and tested. Then we can talk more about where you're stuck.
For a little bit of sanity, I'm including a small amount of code which I've verified compiles, and am reasonably certain will work. If you would like to use it, feel free, but -you- are responsible for testing it.
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
// generic class for a Bank Account
class BankAccount
{
protected:
int accNumber;
float balance;
public:
BankAccount(int acctNo, float bal=0.0);
bool matchesAccountNum(int acctNo);
float getBalance();
void deposit(float amount);
void withdraw(float amount);
void display();
};
BankAccount::BankAccount(int acctNo, float bal):
accNumber(acctNo), balance(bal)
{
}
bool BankAccount::matchesAccountNum(int acctNo)
{
return (accNumber == acctNo);
}
float BankAccount::getBalance()
{
return balance;
}
void BankAccount::deposit(float amount)
{
balance = balance + amount;
}
void BankAccount::withdraw(float amount)
{
// fix this: read your assignment sheet, it tells you exactly how this
// should behave!
balance = balance - amount;
}
void BankAccount::display()
{
printf("Generic Bank Account\n");
printf(" account number: %d\n", accNumber);
printf(" balance: $%.2f\n", balance);
}
// derived Savings Account class
class SavingsAccount : public BankAccount
{
protected:
// inherits accNumber and balance from BankAccount
float interestRate;
public:
// inherits matchesAccountNum(), getBalance(), deposit() as-is from
// BankAccount
SavingsAccount(int acctNo, float bal=0.0, float iRate=0.0);
void applyInterest(float fractionOfYear);
// overridden methods from BankAccount
void withdraw(float amount);
void display();
};
SavingsAccount::SavingsAccount(int acctNo, float bal, float iRate):
BankAccount(acctNo, bal), interestRate(iRate)
{
}
void SavingsAccount::applyInterest(float fractionOfYear)
{
balance = balance + balance*(interestRate * fractionOfYear);
}
// override these inherited methods
void SavingsAccount::withdraw(float amount)
{
if (amount > balance) {
// can't overdraw your SavingsAccount, do something else here
// (hint: read your assignment sheet)
}
else
balance = balance - amount;
}
void SavingsAccount::display()
{
printf("Savings Account\n");
printf(" account number: %d\n", accNumber);
printf(" annual interest rate: %%%.1f\n", interestRate*100);
printf(" balance: $%.2f\n", balance);
}