![]() |
| ||
| A Puzzling Address Book... Hello, I am a new programmer attempting to tackle this puzzle after a couple of setbacks. I was excited about this project, but I am very stuck, and I am not sure where to go, or even if I'm on the right track. Okay, so let's get down to the problem: I am trying to write an address book; it needs to have ten people in it but right now I have everything set for two just for the sake of testing everything. (It takes ages to write in ten sets of addresses!) Anyway, what it needs to do is take the information of the people from the user and put it into an array of structures. What I am working on right now is the addPerson and getPerson functions: I'm not even going to worry about the others untill I can understand them better. The addPerson function should copy the structure passed to it to the end of the array. The getPerson should start at array element 0 and with each successive call return the next person in the array. Both of these functions need to take a reference from a structure called PERSON, which is where all of the fields for the first and last names, and the address should be. //Structure definition Person. Now, this section is the functionality of the program. (this is my first time using a header file) //.cpp file I know that it is very rough, I am having a lot of trouble with my memory right now and that doesn't mix with learning new things. I would really appreciate some help, but I also want to say that this is my homework so please do not post a full answer: I really, really want to learn! I just need help with some explanations about structs and maybe how to use them in a situation like this. I'm not sure if I am referencing it properly in the functions with PERSON p. I also am trying very quickly to re-learn about arrays and how to manipulate them. If you can point me in the right direction, I would greatly appreciate it. Thank you very much, in advance :) |
| ||
| Re: A Puzzling Address Book... You're off to a good start, here are some little tips/observations that might help you: 1/ Your header file should contain the structure definition as well as the function prototypes for functions related to that structure. So basically you should move the function prototypes into your header. Remove the last line of the header, you do not need/want it there. 2/ You will need some variable that keeps track of how many people are currently in the address book. You need this so that you know where in the array to add a person. 3/ In you addPerson(), you do not need to loop, and you should not redeclare the array. Instead you should copy the contents of the given person to the index of the array that you are currently on (as mentioned in #2). 4/ getPerson() should not loop either. You should have a variable somewhere that keeps track of what index you have looked at last so that the next time you call this function, you can get the next person after that (and increase the index). |
| ||
| Re: A Puzzling Address Book... Please see my comments in the code. //Structure definition Person. //.cpp file |
| ||
| Re: A Puzzling Address Book... Thank you very much for taking the time to help me. I am going to play around with this and I'll reply with some of the questions that I will have then. |
| ||
| Re: A Puzzling Address Book... Thank you very much for your advice. This was helpful, and I appreciate it. |
| ||
| Re: A Puzzling Address Book... All right, well, this is almost done. I think. I believe I need some help with my switch structure. I think I am done with the logic of most of the functions. If someone can give me some advice or a push in the right direction, I would really appreciate it. I'm not going to post the function code in this thread because I know this website's policy about free homework, and this project is my homework. i don't want to give someone else the homework for this class. So here is my main function, perhaps someone can see what is wrong with the switch :) int main() Alright, well, when I run this program, I get five warnings because of stricmp, but I'm not worried about that. What I need to know, is why my switch isn't working. If you need more info to help me figure it out, I will be playing around with it too, so I might be able to tell you more about it in a little while... |
| All times are GMT -4. The time now is 7:12 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC