@sierranm
Consider these points:
1. Set functions are only needed if a member variable needs to be changed
after it has been created. An initialiser list initialises member variables as the object is being created - technically before the code in the body of the constructor is executed. You probably don't need any set functions !! If you do actually need them, then they should have code to check that the operation is authorised - we don't want a trivial function like this:
sierra.SetBankBalance(-1000000.00); // instant $1million mortgage!!
There is also no need to call a set function to set a member variable - class functions have direct access to member variables. All this is negated by using the initialiser list.
2. get (accessor) functions return the value of a member variable, not get input from the user. They should be marked
const
as they don't change the value of any of the member variables. But seen as you have the display function, you won't need any get functions either!!
3. Get input from the user, validate it,
then create the object - we want to create a valid object. This all happens outside the class, and not inside the constructor.
4. Avoid using global variables, the filename & stringstreams could exist in
main()
function scope say.
Changing variable names isn't hard - use find & replace in your IDE or editor. Hopefully your IDE has some refactoring functions which change the names of things everywhere not just in he file you are in. Similarly with placing
std::
in the appropriate places, you only have cout, cin, string, endl. If you miss any the compiler will tell you. With
std::endl
, I only use it occasionally because it flushes the buffer, say at the end of a for loop or function, otherwise use the
\n
character.
How do you use toupper and tolower with string? |
std::toupper
works with
char
, and there is another C++ version with a locale, rather than the C version:
More stuff to think about ..... :+D