C++ Error, please help. My brain is just a little fried, I wrote this in the las
ID: 3787387 • Letter: C
Question
C++ Error, please help.
My brain is just a little fried, I wrote this in the last 10 hours. I'm receiving the following errors at the end of my cpp. I know they are not shown to be declared, but I'm fried, please assist with where to put them to declare.
[Error] 'class bankAccount' has no member named 'print'
[Error] 'class bankAccount' has no member named 'createMonthlyStatement'
/////////////////////////////////
//main.cpp
////////////////////////////////
#include
#include
#include
#include
#include "bankAccount.h"
#include "SavingsAccount.h"
#include "HighInterestSavings.h"
#include "NoServiceChargeChecking.h"
#include "ServiceChargeChecking.h"
#include "HighInterestChecking.h"
#include "CertificateOfDeposit.h"
#include "checkingAccount.h"
using namespace std;
int main()
{
vector accountsList;
//SavingsAccount( Name, Account number, Balance ) - Assume an interest rate = 0.03
accountsList.push_back(new SavingsAccount("Bill", 10200, 2500));
//HighInterestSavings(Name, Account Number, Balance) -- Assume an interest rate = 0.05, Minimum balance = $2500
accountsList.push_back(new HighInterestSavings("Susan", 10210, 2000));
//NoServiceChargeChecking(Name, Account Number, Balance) -- Assume an interest rate = 0.02, Minimum balance = $1000
accountsList.push_back(new NoServiceChargeChecking("John", 20100, 3500));
//ServiceChargeChecking(Name, Account Number, Balance) -- Assume account service charge = $10, Maximum number of checks = 5, Service Charee Excess Number of Checks = $5
accountsList.push_back(new ServiceChargeChecking("Ravi", 30100, 1800));
//HighIntererestChecking(Name, Account Number, Balance) - Assume an inerest rate = 0.05, Minimum balance = $5000
accountsList.push_back(new HighInterestChecking("Sheila", 20200, 6000));
//Certificate(name, Account Number, Balance, Interest Rate, Number of Months) - Assume an initial interest rate = 0.05, Initial Number of Maturity Months = 6
accountsList.push_back(new CertificateOfDeposit("Hamid", 51001, 18000, 0.075, 18));
cout << "January: -------------" << endl;
for (int i = 0; i < accountsList.size(); i++)
{
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
cout << endl;
}
cout << " February: -------------" << endl;
for (int i = 0; i < accountsList.size(); i++)
{
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
cout << endl;
}
for (int i = 0; i < accountsList.size(); i++)
{
accountsList[i]->withdraw(500);
}
cout << " March: -------------" << endl;
for (int i = 0; i < accountsList.size(); i++)
{
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
cout << endl;
}
system("pause");
return 0;
}
////////////////////////////////////////
//bankAccount.h
////////////////////////////////////////
#include
#include
#include
#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H
using namespace std;
class bankAccount
{
public:
bankAccount(string name, int acctNum, double initialBalance)
{
m_Name = name;
m_AcctNumber = acctNum;
m_Balance = initialBalance;
}
~bankAccount(void){}
string get_Name()
{
return m_Name;
}
int get_AcctNumber()
{
return m_AcctNumber;
}
double get_Balance()
{
return m_Balance;
}
void deposit(double amount)
{
m_Balance += amount;
cout << "$" << amount << " has been deposited to your account" << endl;
}
virtual void withdraw(double amount) = 0;
virtual void printStatement() = 0;
virtual void printSummary()
{
cout << setw(60) << setfill('-') << "" << setfill(' ') << endl;
cout << endl << setw(25) << "" << "Account Summary" << endl << endl;
cout << setw(25) << "Name: " << m_Name << endl;
cout << setw(25) << "Account #: " << m_AcctNumber << endl;
cout << setw(25) << "Current Balance: $" << m_Balance << endl;
}
protected:
string m_Name;
int m_AcctNumber;
double m_Balance;
};
#endif
Explanation / Answer
Hi, You are calling
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
these two methods on each bankAccount type but,
I can see there are no 'print' and 'createMonthlyStatement' methods declared in 'bankAccount.h' file
You have to also provide the defination of these two methods in '.cpp' file
#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H
using namespace std;
class bankAccount
{
public:
bankAccount(string name, int acctNum, double initialBalance)
{
m_Name = name;
m_AcctNumber = acctNum;
m_Balance = initialBalance;
}
~bankAccount(void){}
string get_Name()
{
return m_Name;
}
int get_AcctNumber()
{
return m_AcctNumber;
}
double get_Balance()
{
return m_Balance;
}
void deposit(double amount)
{
m_Balance += amount;
cout << "$" << amount << " has been deposited to your account" << endl;
}
virtual void withdraw(double amount) = 0;
virtual void printStatement() = 0;
virtual void printSummary()
{
cout << setw(60) << setfill('-') << "" << setfill(' ') << endl;
cout << endl << setw(25) << "" << "Account Summary" << endl << endl;
cout << setw(25) << "Name: " << m_Name << endl;
cout << setw(25) << "Account #: " << m_AcctNumber << endl;
cout << setw(25) << "Current Balance: $" << m_Balance << endl;
}
virtual void createMonthlyStatement() = 0;
virtual void print() = 0;
protected:
string m_Name;
int m_AcctNumber;
double m_Balance;
};
#endif
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.