Hey guys, i am struggling with an inherited class i am creating but for some reason the wheels have fallen off and i cant figure out why.
below base class header file:
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
|
#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H
class bankAccount
{
public:
void setAccountNumber(int number);
//Function to set account number.
//The member variables accountNumber
//is set according to the parameters.
//Postcondition: accountNumber = number;
int getAccountNumber() const;
//Function to return the account number.
//Postcondition: The value of accountNumber is returned.
void setAccountBalance(double balance);
//Function to set account balance.
//The member variables accountBalance
//is set according to the parameters.
//Postcondition: accountBalance = balance;
double getAccountBalance() const;
//Function to return the account balance.
//Postcondition: The value of accountBalance is returned.
void acceptDeposit(double deposit);
//Function to receive the amount depositied by
//the customer and update the amount in the account.
//Postcondition: accountBalance = accountBalance + deposit;
void acceptWithdrawal(double withdrawal);
//Function to withdraw money from the account
//and to update the amount in the account.
//Postcondition: accountBalance = accountBalance - withdrawal;
void printAccount() const;
//Function to output the account details in the form
//Account Number: XXXXXXXXX
//Account Balance: R0.00
bankAccount(int number = 0, double balance = 0);
//Constructor to set the bank account number and balance.
//The member variables accountNumber and accountBalance
//are setaccording to the parameters.
//Postcondition: accountNumber = number, accountBalance = balance
// If no values are specified, the default
// values are used to initialize the member
// variables.
protected:
int accountNumber;//variable to store account number.
double accountBalance;//variable to store account balance.
};
#endif // BANKACCOUNT_H
|
base class implementation file below:
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
|
#include <iostream>
#include <iomanip>
#include "bankAccount.h"
using namespace std;
void bankAccount::setAccountNumber(int number)
{
accountNumber = number;
}
int bankAccount::getAccountNumber() const
{
return accountNumber;
}
void bankAccount::setAccountBalance(double balance)
{
accountBalance = balance;
}
double bankAccount::getAccountBalance() const
{
return accountBalance;
}
void bankAccount::acceptDeposit(double deposit)
{
accountBalance = accountBalance + deposit;
}
void bankAccount::acceptWithdrawal(double withdrawal)
{
accountBalance = accountBalance - withdrawal;
}
void bankAccount::printAccount() const
{
cout << fixed << showpoint << setprecision(2);
cout << "Account Number: " << accountNumber << endl;
cout << "Account Balance: R" << accountBalance << endl;
}
bankAccount::bankAccount(int number, double balance)
{
accountNumber = number;
accountBalance = balance;
}
|
below code for header file of problem class
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
|
#ifndef SAVINGSACCOUNT_H
#define SAVINGSACCOUNT_H
#include "bankAccount.h"
class savingsAccount : public bankAccount
{
public:
void setInterestRate(double interest);
//Function to set account interest rate.
//The member variable interestRate
//is set according to the parameters.
//Postcondition: interestRate = interest;
double getInterestRate() const;
//Function to return the account interest rate.
//Postcondition: The value of interestRate is returned.
void acceptWithdrawal(double withdrawal);
//Function that first checks to see if there is enough funds
//in the account. If there are enough funds the amount is withdrawn
//from the account and the remaining funds updated.
//If there is not enough funds a message is returned.
//Postcondition: if (accountBalance >= withdrawel)
// accountBalance = accountBalance - withdrawal;
// else
// insuficient funds;
void setInterest();
//Function to set account interest earned.
//The member variable interestEarned
//is set according to the parameters.
//Postcondition: interestEarned = interest;
double getInterest() const;
//Function to return the account interest earned.
//Postcondition: The value of interestEarned is returned.
void printCheck() const;
//Function to output the account details in the form
//**************************
//Savings Account
//**************************
//Account Number: XXXXXXXXX
//Account Balance: R0.00
//**************************
savingsAccount(int num = 0, double bal = 0, double intRate = 3, double intEarned = 0);
//Constructor to set the bank account number, balance, interest rate and interest earned.
//The member variables accountNumber, accountBalance, interestRate
//and interestEarned are set according to the parameters.
//Postcondition: accountNumber = num, accountBalance = bal
// interestRate = intRate, interestEarned = intEarned.
// If no values are specified, the default
// values are used to initialize the membervariables.
private:
double interestRate;//variable to store interest rate.
double interestEarned;//variable to store interest earned.
#endif // SAVINGSACCOUNT_H
|
and then code for implementation file that is giving a lot of errors i dont understand and cant figure out...
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
|
#include <iostream>
#include <iomanip>
#include "savingsAccount.h"
using namespace std;
void savingsAccount::setInterestRate(double interest)
{
interestRate = interest;
}
double savingsAccount::getInterestRateSaving() const
{
return interestRate;
}
void savingsAccount::acceptWithdrawalSaving(double withdraw)
{
if (accountBalance >= withdraw)
accountBalance = accountBalance - withdraw;
else
cout << "Insuficient funds!" << endl;
}
void savingsAccount::setInterestSaving()
{
interestEarned = accountBalance * (interestRate/100);
}
double savingsAccount::getInterestSaving() const
{
return interestEarned;
}
void savingsAccount::printCheckSaving() const
{
cout << "**************************";
cout << "Savings Account";
cout << "*************************";
bankAccount::printAccount();
cout << "*************************";
cout << endl;
}
savingsAccount::savingsAccount(int num, double bal, double intRate, double intEarned)
{
bankAccount(num, bal);
interestRate = intRate;
interestEarned = intEarned;
}
|
Below errors experienced:
error: expected nested-name-specifier before 'namespace'
error: extra qualification 'savingsAccount::' on member 'setInterestRate
error: 'void savingsAccount::setInterestRate(double)' cannot be overloaded
error: with 'void savingsAccount::setInterestRate(double)'
error: extra qualification 'savingsAccount::' on member 'getInterestRateSaving'
The list goes on...