bank account class heirarchy

im having trouble figuring out what is wrong with my code for this bank account class. I can say i am not the best at c++ and im not sure if i even got any of this right. Can someone please help


i am also getting the error LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) Account Inheritance Heirarchy and the error Severity Code Description Project File Line Suppression State Error LNK1120 1 unresolved externals Account Inheritance Heirarch i am also using microsoft visual studio 15

#include <iostream>
using namespace std;

//account header file

#ifndef account_h
#define account_h

class account
{

public:
account(double bal);
double credit(double value);
bool debit(double value);
double getBalance();
void setBalance(double bal);

private:
double balance;




};

#endif


//account.cpp file//


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


account::account(double bal)
{
if (bal<0)
{
cout << "\n Invalid Balance. Balance will be set to 0";
balance = 0;
}
else
{
balance = bal;
}
}

double account::credit(double value)
{
if (value >= 0)
balance += value;
else
cout << "\n Invalid Value" << value;
return balance;
}
bool account::debit(double value)
{
bool enoughfunds;
{

if (value > balance)
{
enoughfunds = false;
cout << "Insufficient Funds" << balance;

return false;


}
else
{
enoughfunds = true;
balance -= value;
cout << "Transaction completed succcessfully." << endl;
cout << "You're current balance is" << endl;

return true;

}
}
}
double account::getBalance()
{
return balance;
}

void account::setBalance(double bal) {
balance = bal;

}



//savingaccount.h



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


#ifndef savingaccount_h
#define savingaccount_h


class savingaccount : private account
{
public:
savingaccount(double bal, double percentage);
double calculateIntrate(double percentage, double bal);
double getIntrate();
void setIntrate(double percentage);

private:
double intrate;
};

#endif



//savingaccount.cpp//


#include <iostream>
#include "savingaccount.h"


using namespace std;

savingaccount::savingaccount(double bal, double percentage) :account(bal)
{
double balance = bal;
double intrate = percentage;
}
double savingaccount::calculateIntrate(double percentage, double bal)
{
return bal*(percentage / 100);

}

double savingaccount::getIntrate() {
return intrate;
}
void savingaccount::setIntrate(double percentage) {
intrate = percentage;
}
//checking account .h//

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


#ifndef checkingaccount_h
#define checkingaccount_h


class checkingaccount : private account

{
public:
checkingaccount(double bal,double Cfee);
double Chargefee(double bal, double Cfee);
double getfee();
void setfee(double Cfee);


private:
double fee;
};
#endif


//checkingaccount.cpp//


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


checkingaccount::checkingaccount(double bal, double Cfee) :account(bal)
{
double balance = bal;
double fee = Cfee;

}
double checkingaccount::Chargefee(double bal,double Cfee)
{
if ((bal - fee) >= 0)
{
bal -= fee;
cout << "Fee charged succcessfully.\n";
return true;
}
else {
return false;

}
}
double checkingaccount::getfee()
{
return fee;
}
void checkingaccount::setfee(double Cfee)
{
fee = Cfee;

}

//main//

#include <iostream>
#include "account.h"
#include "savingaccount.h"
#include "checkingaccount"
using namespace std;

int main()
{
account bankaccount;

bankaccount.getbalance(10000);
cout << "You're balance is" << bankaccount.getBalance;

}
Last edited on
The "unresolved external symbol" error you are experiencing is most likely due to you having selected an incorrect project template when you created your project. You may alleviate this by doing one of the following:

1.) Copy your code, create a new "Win32 console application" project, paste your code.

or

2.)
a.) Right-click your project's name in the solution explorer.
b.) Select "Properties"
c.) Navigate to "Linker > System"
d.) Make sure the "Configuration" drop-down menu at the top left corner says "Debug"
e.) Click on the "Subsystem" field, a drop-down menu should appear
f.) Select "Console (/SUBSYSTEM:CONSOLE)"
g.) Click "Apply"
h.) Now change the "Configuration" drop-down menu at the top left corner from "Debug" to "Release"
i.) Perform steps e.) through g.)
j.) Click "OK"

This will reconfigure your project, and lift the "unresolved external symbol" error.


I haven't really looked at your code, but you'll want to change some code in your main function. Here's what you've written:

1
2
3
4
5
6
7
8
int main()
{
	account bankaccount;

	bankaccount.getbalance(10000);
	cout << "You're balance is" << bankaccount.getBalance;

}


1.) On line 3 you instantiate an 'account' object, however, 'account' has no default constructor. The only constructor that exists for 'account' is one that expects a double argument, so either give the 'account' class a default constructor, or pass a double to bankaccount's constructor on line 3 of your main function (or both).

2.) Line 5 has the most problems. Your class 'bankaccount' doesn't have a member function named 'getbalance'. It does, however, have one named 'getBalance'. C++ is case-sensitive.
Additionally, 'getBalance' doesn't take any arguments, but you're passing the integer 10000 to it. Remove the argument.
Finally, you're not doing anything with the result that this function returns. You'll have to assign this value to some variable. This change will also have to be reflected in line 6 where you print the balance.

1
2
3
4
5
6
7
8
int main()
{
	account bankaccount(500.0);

	double balance = bankaccount.getBalance();
	cout << "Your balance is" << balance;

}
Last edited on
Topic archived. No new replies allowed.