Ok, making some progress.
I would have 3 files:
1 Account.h
2 Account.cpp #include Account.h
3 BankingSystem - Main is in this file #include Account.h
Now that you have all your functions in the class, you can get rid of all those set & get functions.
To think about why that is, consider this work flow:
1: Create the private functions you need
2: Create the private variables the functions need. If the variable is something only that function will need it can be local to that function ( that is, declared inside it)
3: Decide which functions should be public, that is can be called by the object in main say
4: If there are any variables that need to be public, provide a public function that returns the private variable.
Remember, a private variable can be accessed by any function in the class, that is why we don't need all those get & set functions.
The code you have in your current BankingSystem.cpp is the ShowMenu function - this should go in the same file as main().
I am guessing that this project implements a simple banking system in that Deposit or withdraw functions only alter the account balance, the transactions themselves aren't stored. If you do want to store transactions you will need some more classes.
So my reason it goes in the main application file and not in either of the Account files, is that the menu applies to the whole system and not just to one class.
Now the next improvement, would be to have a ProcessMenu function (also in the main application file). This would contain the switch statement that calls the functions to carry out each menu option.
Then you could have something like this in main():
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
while (selection !=6) {
ShowMenu();
cout << "Please Enter a New Selection";
cin >> selection;
ProcessMenu(selection);
}
You can see how the above snippet is easy to understand as a unit, rather than say 200 lines of code.
This should be in main(), not in Account.cpp
[code]// Create a new account
Account newAccount;
|
The idea is to create the object in main, then use it to call the objects functions.
[/code]
before main()
1 2 3 4 5 6 7
|
//////////////////////////////////////
//Function declarations
/////////////////////////////////////
void ShowMenu();
void ProcessMenu(unsigned short selection);
|
After main()
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
|
void ShowMenu() { //this function is easy to understand as a unit
cout << "Welcome to My Banking System" << endl;
cout << "(1) Add account\n";
cout << "(2) Delete Account\n";
cout << "(3) Account Inquiry\n";
cout << "(4) Save Accounts to File\n";
cout << "(5) Load Accounts from File\n";
cout << "(6) Exit" << endl; //endl same as \n but it flushes the buffer
}
void ProcessMenu(unsigned short selection) { //this is easy as well, the work is carried out by
//the class functions
switch (selection)
{
case 1:
//call the CreateAcct function - better name than AddAccount
NewAccount.CreateAcct()
break;
case 2:
//call the DeleteAcct function - better name
NewAccount.DeleteAcct()
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
cout << "Exiting program"
exit(0); //exits the whole program
break;
default:
cout << "Invalid selection. Please Choose another option\n";
break;
}
}
|
Now I really wish you wouldn't name your variables with underscores.
1 2 3 4 5 6 7
|
private:
string _accountNumber;
string _passCode;
string _lastName;
string _firstName;
double _balance;
double _startingBalance;
|
The thing to do, is name your member variables with m_ at the start and capitalise the first letter of each word in the variable name like this:
1 2 3 4 5 6 7
|
private:
string m_AccountNumber;
string m_PassCode;
string m_LastName;
string m_FirstName;
double m_Balance;
double m_StartingBalance;
|
That way, if you do have functions that take arguments, the arguments won't be confused with the member variables.
I think the reason you are doing it is because you want to have a similar name for function arguments. The thing is you don't need arguments for these functions - the variables are already there in the class.
There is no need to declare these functions, they should be in the class.
1 2 3
|
void addAccount(vector<Account> &accounts);
void deleteAccount(vector<Account> &accounts);
int main()
|
The other confusion is, there are 2 things: One, the account object (NewAcct) say, and Two, a group of (vector) account objects. The vector of account objects could be in main(), then you need logic to handle dealing with a particular account. I would recommend getting every thing to work for 1 acct, then extend it to handle multiple accts with a vector or list. Another way would be to have another class that stored the list of accts - I might have to think about how that would work.
Ok, I hope that this has sorted out the framework for the app, & you can understand how things work with classes.
Good luck, I look forward to helping out some more.