I have an assignment that I am almost finished with but I am trying to figure out why my code won't compile. I believe the issue to be minor but I can't seem to figure out the bug. The problem call for me to build an inheritance heirarchy that a bank may use. The base class is 'Account' and the derived classes 'SavingsAccount' and 'CheckingAccount' inherit from this account.
Here is my Header for and source for class Account
#ifndef Account_H
#define Account_H
using namespace std;
class Account
{
private:
double balance;
public:
Account(double =0.0);
void credit(double add);
void debit(double sub);
double getbalance();
};
#endif
#include <iostream>
#include "Account.h"
using namespace std;
Account::Account(double amount)
{
if (amount <=0.0)
{
balance =0.0;
cout<<"Initial balance must be greater than 0"<<endl;
}
else balance = amount;
}
void Account::credit(double add)
{
balance +=add;
}
void Account::debit(double sub)
{
if (sub > balance)
{
bool r = false;
while (r!=false)
{
balance-=sub;
}
}
double Account::getbalance()
{
return balance;
}
Here is my header and source for class SavingsAccount
#ifndef SavingsAccount_H
#define SavingsAccount_H
using namespace std;
class SavingsAccount : public Account
{
public:
SavingsAccount(double amount,double rate);
double CalculateInterest();
private:
double interestRate;
};
#endif
#include <iostream>
#include "SavingsAccount.h"
using namespace std;
SavingsAccount::Account(double amount,double rate)
{
:Account(amount)
{
interestRate = rate;
}
SavingsAccount::CalculateInterest()
{
double interest;
return interest = balance * rate/12;
}
Here is my header and source for CheckingAccount
#ifndef CheckingAccount_H
#define CheckingAccount_H
using namespace std;
class CheckingAccount : public Account
{
private:
double transactionFee;
public:
CheckingAccount(double amount, double fee);
void double credit(double add);
void double debit(double sub);
};
#endif
#include <iostream>
#include "CheckingAccount.h"
using namespace std;
CheckingAccount::CheckingAccount(double amount,double fee)
{
:Account(amount)
{
transactionFee = fee;
}
CheckingAccount::credit(double add)
{
Account::credit(add-fee)
}
CheckingAccount::debit(double sub)
{
Account::debit(sub+fee)
}
I keep getting compile errors on account in the source code. I can't figure out how to correctly implement the getbalance() function and getting it to compile. Also having other compile errors but this may be the cause for them as well. Any help would be appreciated.