I am a bit dismayed that your instructor has given you this code.
As I said earlier, I don't think that any of the get or set functions are necessary.
CreateAccount
is a class function, so it has direct access to the class variables -> no need for set functions.
BankingSystem::PrintAccounts()
would call
Account::PrintThisAccount()
which is also a class function with direct access to it's member variables - so no need for any get functions.
Update functions (not trivial set functions) are only necessary when the data changes after the object has been created, this is the case with the Deposit & Withdraw functions which will have checking and validation code in them.
Get functions might only be needed when another class needs access to the data, even then there are ways around that - see the discussion about Send & Receive functions in the getters / setters Topic.
The .cpp file is confusing in it's layout, IMO there should be these files : BankingSystem.h, BankingSystem.cpp, Account.h and Account.cpp. The class declarations go in the relevant .h file, while the function definitions go in the relevant .cpp file. The header file is
#include
in which ever file needs it (that is, involves an object of that type), namely the .cpp files and in main.cpp.
Now you could get away with not having any get / set functions, it's not cheating:
you just need to explain all your good reasons to your instructor. I would be honest and show s/he the advice you have received on this forum.
When I am suppose to GET the remaining functions...Should I use getLastName.... or should I use a more practical approach like what I am trying to do with cout and cin. |
There is a slight difference in the meanings. A get function returns a value, which is a different thing to asking the user for input for the account number say. The code could go in a private function which is called by whatever function that needs it. Naming is important, try AskAccountNumber for example. Checking whether an account exists is another candidate for a private function, along with ones that ask for filenames, and asking for the Pass Code.
With the file processing, the BankingSystem class should have 2 functions : that load data from a file, in turn calling the Account constructor - populating the accounts array ; and one that save the data to a file, by iterating through the array, calling the
Account::PrintAcountToFile()
function say.
main() should only have code that creates the necessary objects, and calls their member functions with nothing else. A ShowMainMenu() function could go in the BankingSystem class, seeing that it only deals with this class and not multiple other classes. This is easy because it can call the necessary functions directly. More advanced would be to put it in a class of it's own, but that is a tiny bit trickier to call the functions, and maybe not worth it for this example. A justification for doing it any way would be that it makes it easier to extend later on.
Did I show this link for how to use a while loop & switch for a menu?
Any way see how you go with all that :+)