I am currently working on a banking system that has 3 classes. customer, savingsAccount and transaction. I have created the 3 classes but am having problems with the saveAcnt object in the customer class. I need to link it with the savingsAccount class. Any help would be appreciated.

Also I should note that each class is located in its own header file and they are all #include'd in the main cpp program.

/*
savingsAccount.h
*/
#include <iostream>
using namespace std;

class savingsAccount
{
public:
    void createAccnt(int, double, double);
	void addDeposit(double);
	void subWithdraw(double);
	void addInterest();

private:
    int accntNo;
    double balance;
    double iRate;
};

//Main program defines accountNo, bal and interest and then passes to createAccount
void savingsAccount::createAccnt(int accountNo, double bal, double interest)
{
	accntNo = accountNo;
	balance = bal;
	iRate = interest;
}
/*transaction.h
*/
#include <iostream>
using namespace std;

class transaction
{
public:
    void readRecords(ifstream);
	//int findAccount(Customer[], int);
	//void process(Customer[]);

private:
    int accountNumber;
    double amount;
    char transType;
};
/*customer.h
*/
#include <iostream>
using namespace std;

//class savingsAccount;

class customer
{
public:
    void createCust(string, string, int);
	bool searchAccount(int);
	void applyTrans(char, double);
	void accessAccount(char);

private:
    string name;
	string address;
	savingsAccount saveAccnt;
};

void customer::createCust(string custName, string custAddress, int custSavingsAccnt)
{
	name = custName;
	address = custAddress;
	//saveAccnt = custSavingsAccnt;
}

add

#include"savingsAccount.h"

in the file "customer.h"

As soon as I add that line of code I get a whole list of errors all to do with my functions already being defined.

I should also point out that the line of code that is causing the issue for me is line 26 in customer.h. Currently commented out (I was testing the rest of it was working).

Also, in the main I am inputting data into the savingsAccount using an array of the class savingsAccount and just inputting the data that way. Then I am attempting to do the same with the customer class by using an array (of the same size as the savingsAccount array) and then just inputting but not sure what I am meant to be passing to the createCust() function within the customer class.

Below is one of the inputs for the array savingsAccount followed by one for customer, so you can see how I am working it atm.

//savingsAccount
savingsAccount accnts[6];
accnts[0].createAccnt(16428,0.0,0.05);

//customer
customer cust[6];
cust[0].createCust("John Citizen","4 Example Street",accnts[1].getAccntNo());

#include "savingsAccount.h" in customer.h

Line 6 in customer.h is a forward declaration. It works only if the usage following declaration is by-reference/pointer.

line# 26:
you are trying to assign an integer to a variable of type "savingsAccount". Correct this first.


Regarding the compilation:
Show me how you are trying to compile and create the executable file. Because just including a file cannot build the complete executable, you have to link the object files as well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.