Hi silversidewalkstew,
OK, I think you need a bit of reorganising here, to get rid of all your get & set functions, so that your current errors will go away.
Firstly, remember that class functions have direct access to class member variables, despite their declared access specifier. In other words, a class function has direct access to the member variables even though they might be private or protected.
Also, there is the concept of initialiser lists.
So, you can make use of these two things to get rid of all your set functions.
The constructor you have on lines 9 to 23, could look like this :
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
Account::Account( int accountNumberValue,
int passCodeValue,
string lastNameValue,
string firstNameValue,
double balanceValue
) : // Colon introduces the initialiser list
accountNumber(accountNumberValue),
passCode(passCodeValue),
lastName(lastNameValue),
firstName(firstNameValue),
balance(balanceValue);
{} // no need for any code in here
|
It is usual practice to have the initialiser list in the same order as what is in the class declaration, You haven't shown that file, so I am not sure whether the order shown is correct or not.
You could also get rid of all your get functions as well, in main() you are using them instead of creating an object with an appropriate constructor - the code I have shown above.
Initialiser lists are better than assignment because it happens during construction of the object rather than after, and in your case avoids a bunch of getter & setter functions.
We had a huge discussion about getters & setter functions a while back, It might be worth your while to read it. It is a bit long at 7 pages, but there is some good stuff in there. In general, trivial use of them is bad, especially setters, but there are situations where they are warranted. IMO beginners should avoid routinely using them in a trivial manner.
It is important to realise the difference between a setter function & an update function. The latter has code that checks & validates, as in a withdrawal function.
Now the other big concept is the idea of encapsulation. Part of that says that every function that operates on an object should be a member function of that class. So in main() functions like outputLine & getAccount should be class functions IMO.
The outputLine function is a good example of how not to use getter functions. Prefer to have a class function called PrintThisAccount say.
Also, I am a bit sceptical about your approach of over writing parts of files directly, because it could be error prone. What happens if you manage to have duplicate account numbers? You don't seem to have code that checks for that.
By making use of an appropriate STL container like
std::map
or
std::set
along with the
[]
operator, one can do this easily. Use of those containers might be beyond the scope of your course, but even with a
std::vector
it would be better.
At this level, it would be perfectly fine & much better to read all the values from a file into a
std::vector
say, make the modifications to the data in the vector, then write the whole vector out to a new file when finished.
The BankingSystem class should have a member which is a
std::vector
(if you were to use this container say) of Account objects. This class should have all the functions for : Creating, deleting, finding accounts ; while the Account class has functions for dealing with details of an Account.
Also the use of
reinterpret_cast
is a clue that the OO design is not as good as it could be.
And you should prefer the use of
std::string
over char arrays.
Now all this means a bit of work for you, but I hope you realise that it will vastly improve your code, and should help you get much better marks for your assignment. And it should give you a much better approach to the way you design your code in the future.
Hope all goes well, I look forward to helping for any other queries you may have.