im a new student to c++ and classes has really confused me. the program is creating a bank account. i have already completed the header file but the implementation file has be confused. can someone please help me with this. thanks!
here is my header file:

#include <iostream>
using namespace std;
class BankAccount
{
private:
string id;
double balance;
string password;
public:
BankAccount();
BankAccount(string,double,string);
string getID();
double getBalance();
void setID(string);
void setPassword(string);
bool deposit(double);
bool withdrawal(double);
void addInterest();
bool equals(BankAccount);
string getPassword();
}

You're missing a ; at the end of that.

See each one of those function? This list:

BankAccount();
BankAccount(string,double,string);
string getID();
double getBalance();
void setID(string);
void setPassword(string);
bool deposit(double);
bool withdrawal(double);
void addInterest();
bool equals(BankAccount);
string getPassword();

You need to make each one of those. I'll get you started, and then you make the rest.

BankAccount::BankAccount()
{
  id = "";
  balance = 0;
  password = "";
};

Edited 5 Years Ago by Moschops: n/a

thanks for the help. i have one more question.
will it always be set up like bankaccount::(then something)?
like will the next one look like
bankaccount::bankaccount(string,double,string)?

C++ is case sensitive so bankaccount is not the same as BankAccount.

In the .cpp file (if you are using files to keep track of things) you implement the class functions (class methods if you prefer that syntax) declared in the .h file. If you are implementing constructors or destructors you don't need return value but with all other methods you need to preceed the name of the function by the return type, the class name and the ::. Then you need to list all the parameters being sent to the method and be sure each parameter has a name associated with it.

So the non default constructor with three parameters declared in the class BankAccount declaration within the .h file like this:

BankAccount (string, double, string);

would need to be written like this in the .cpp file:
BankAccount::BankAccount(string ID, double amount, string pw) {}
where you put whatever code you want to implement that constructor within the curly brackets.

To implement the getID() method you would start like this:
string BankAccount::getID() {}
and write whatever code you want to use to implement the getID() method within the curly brackets.

The same syntax holds even if you declare and implement your class in you program without using .h and .cpp files.

Edited 3 Years Ago by Dani: Formatting fixed

This article has been dead for over six months. Start a new discussion instead.