Posting your code on the forums would make people more likely to help you, but I can understand not doing so when your code gets to be a couple hundred lines.
1. Your class structure doesn't conform with the assignment.
14 15 16 17 18 19 20 21
|
struct Contact
{
string _firstName[MAX_NUM_CONTACTS];
string _lastName[MAX_NUM_CONTACTS];
string _phoneNumber[MAX_NUM_CONTACTS];
string _emailAddress[MAX_NUM_CONTACTS];
int _numContacts;
};
|
Your class is supposed to contain an array (or vector, or whatever container you want to use) of these.
Contact itself is not supposed to be a contain a bunch of arrays.
2. Line 22,
Contact Contact;
. You named your Contact variable the same as its type. I guess it works, but it's bad practice.
3. Your add function doesn't conform to the programming assignment.
35 36 37 38 39 40
|
void addContact(const Phonebook &Conatcts)
{
cin >> Contact._firstName[Contact._numContacts] >> Contact._lastName[Contact._numContacts];
cin >> Contact._phoneNumber[Contact._numContacts] >> Contact._emailAddress[Contact._numContacts];
Contact._numContacts++;
}
|
A problem here is that you define the parameter as being of the
Phonebook class when your assignment clearly states it should be of type
Contact. You are supposed to actually add the provided
Contact to your array, not ask for input and create the
Contact, then add it. This is made more problematic because of #1 (you aren't using an array of
Contact).
4. These methods are supposed to be part of your class. You should be using the class's methods in your code.
68 69 70
|
void addContact(Phonebook Contact, int numContacts);
void showContact(Phonebook Contact, int numContacts);
void saveContact(Phonebook Contact, int numContacts);
|
5.
Adding contacts seems to work fine but when I try to search for a contact the values within the struct seem to be resetting. |
That's because of the way you implemented those non-member functions in #4 and the way you're using them. It would sort of work if you passed the
Phonebook parameter by reference, but you're passing by value.
That means anything you do to it inside the scope of those functions isn't saved to the actual
Phonebook inside
main.
Haven't finished going over the code, but that answers your original question and gives you enough to think about.