Not writing anything in the cpp file doesn't make sense at all. It's the most reasonable place for all of this code to go.
Like I said earlier, you could use initialisation lists for some of these constructors, but given what you've told me so far you won't have covered them yet. So the cpp file seems right to me.
Right, I don't normally hand out full code because we usually get a lot of people on these forums looks for handouts. On this case, I'll make a bit more of an exception, because I feel you genuinely want to learn it and I think it's the best way to show you.
That way, I can go through it line by line as well.
So, here it goes...
1 2 3 4 5
|
addressBook::addressBook( char *fName, char *lName, char *address )
{
PERSON p = { fName, lName, address };
addPerson( p );
}
|
Probably way simpler than you thought it'd be.
So, what are we doing. We haven't been given a person object, but we've been given the data to create on with. So that's what we'll do.
|
PERSON p = { fName, lName, address };
|
That creates a person object. Rather than hard coding text values like you have in your "TEST1" example a couple of posts ago, we've been given those values in the arguments. So we'll just pass them straight in.
Then we need to add that person to the book. That's easy enough, we've done it before and there's a function for it. So we'll use it.
Remember that "p" in this case is the person object we've just created using the data passed in.
And that's it. :-)