First, I am always dismayed to see this in assignments:
• an accessor function for each member variable (a function that returns that data)
• a mutator function for each member
IMO that introduces a bad habit right from the start. Get functions are reasonably benign, but public set functions are almost always very bad.
byron.setBankBalance(-1000000.00) // instant 1 million dollar mortgage
It also creates misunderstanding about encapsulation
We had a huge discussion about this here:
I wonder whether you could get some brownie points for making use of initialiser lists and constructors (google these), and update functions that set several or all the variables at once.
The purpose of constructors is to initialise data for an object.
Get functions can be avoided by having member functions that do what you want - for example print out all the data for a person, rather than call a function to retrieve each individual member variable.
Anyway, some observations about your problem.
Please indent your code - it makes it easier to understand. If using an IDE this should be automatic. In the IDE format indents to be 4 spaces say not tabs, as tabs are expanded to 8 spaces on this site, so things will display better here if you do that.
With formatting, it would have been nice if you had formatted the assignment part, so it wasn't 5 screens wide on my system!!
You need to
header files for any thing you want to use.
to use strings for example. This will fix a lot of your errors.
Line 46 in your header file - Never include .cpp files, only include header files. Include the header file for the class in the implementation file, and in any other file that needs to use that type of object.
With filenames, name them the same as the class name.
In fields_healthprofile.cpp, your function definitions should have the scope resolution operator, as in:
In your header file, the structs name a type
not an object. You can put an object name after the closing brace.
int month, day, year;
Then refer to items within the struct like this:
DOB.month = 6;
In main(), you don't create an object. This is required so you can call the object's functions defined in the class.
Now there is an idea called encapsulation. This was mentioned in item 2 of the assignment. Part of this means that everything to do with an object (it's data & functions ) should reside in that objects class. So most of the code you have in main() should be in member functions that is part of the HealthProfile class. So you could have one member function that gets all the user input validates it, then assigns it to member variables. At least that keeps it all tidy within the class. See below for more thoughts about this.
Because you app is an interactive one (user types info in) this is a good approach. If you were reading data from a file, then you would define & use constructors to get data into the object.
I just realised I could called out about what I just said. There could be a bit of debate as to which is better:
1. Have a function external to the class, which collects user input, validates it, then uses a constructor with arguments & initialiser list to create the object. This avoids creating an object with bad data. Because the function is external to the class, it is not really encapsulation is it? Would get messy in a bigger application.
2. Create a blank object with a default constructor. Have a member function that does the same as item 1 above, except that member initialisation is by assignment and it throws an exception if data is invalid.
Option 2 sounds better to me.
Any way hopefully all this helps.