diff options
Diffstat (limited to 'Project1/contacts.cpp')
| -rw-r--r-- | Project1/contacts.cpp | 113 |
1 files changed, 59 insertions, 54 deletions
diff --git a/Project1/contacts.cpp b/Project1/contacts.cpp index 2b52062..4de1d59 100644 --- a/Project1/contacts.cpp +++ b/Project1/contacts.cpp @@ -7,13 +7,34 @@ using std::cin; using std::cout; using std::endl; -//getters n setters +// constructors contact_list::~contact_list() { - + delete[] contacts_; + contacts_ = nullptr; +} + +contact* contact_list::allocateContactList(const size_t& size) +{ + contact* contacts = nullptr; + + length_ = size; + + contacts = new contact[size]; + + return contacts; } +contact_list::contact_list(const size_t& size) +{ + length_ = size; + contacts_ = allocateContactList(size); +} + + +//getters n setters + void contact::Set_firstName(const char* firstName) { _firstName = firstName; @@ -123,30 +144,23 @@ size_t contact::Get_id() } //functions -void contact_list::AddContact(const contact& newContact, size_t MAX, size_t& t) -{ - //using couts to prompt using for all parts of newContact struct. - //update plans: check for newContact[i].bool value, if false, use a modified void update - //(new function thats just void update with different couts) to be called with an if statement. - //or another for. - //for (size_t i = 0; i < max/length; i++) - //if (bool == false) - // void mod_update - // to check for any "empty"/deleted contacts before adding one. if bool == false should include break after mod_update. +void contact_list::AddContact(const contact& contact) +{ + contacts_[size_++] = contact; //CURRENTLY TESTING - for (size_t i = 0; i < MAX, i++;) + for (size_t i = 0; i < size_, i++;) { - int a = newContact[i].Get_a(); - for(a = 1; ++i;) + int a = contact.Get_a(); + for (a = 1; ++i;) { - newContact[i].Set_a(0); - int temp = newContact[i].Get_id(); - for (auto j = temp; j < MAX; j++) + contact.Set_a(0); + int temp = contact[i].Get_id(); + for (auto j = temp; j < size_; j++) { - if(newContact[i].Get_id() != 0) - { + if (contact.Get_id() != 0) + { i = i + 1; - } + } } char firstName[30]; char lastName[30]; @@ -155,36 +169,36 @@ void contact_list::AddContact(const contact& newContact, size_t MAX, size_t& t) char City[35]; char State[4]; int Zip = 0; - newContact[i].Set_id(i); + contact.Set_id(i); //newContact[i].Set_a(t); cin.ignore(1000, '\n'); cout << "Please enter each piece of information when you are prompted to" << endl; cout << "enter first name: " << endl; cin >> firstName; - newContact[i].Set_firstName(firstName); + contact.Set_firstName(firstName); cout << "enter last name: " << endl; cin >> lastName; - newContact[i].Set_lastName(lastName); + contact.Set_lastName(lastName); cout << "enter Email: " << endl; cin >> Email; - newContact[i].Set_email(Email); + contact.Set_email(Email); cout << "enter Street Address: " << endl; cin >> StreetAddress; - newContact[i].Set_streetAddress(StreetAddress); + contact.Set_streetAddress(StreetAddress); cout << "enter city: " << endl; cin >> City; - newContact[i].Set_city(City); + contact.Set_city(City); cout << "enter State as two letter abbreviation: " << endl; cin >> State; - newContact[i].Set_state(State); + contact.Set_state(State); cout << "Please enter the next value as a series of numbers" << endl; cout << "enter Zip: " << endl; cin >> Zip; - newContact[i].Set_zip(Zip); + contact.Set_zip(Zip); break; - } + } } - for (size_t i = t ; i < MAX; i++) + for (size_t i = t; i < MAX; i++) { char firstName[30]; char lastName[30]; @@ -193,52 +207,41 @@ void contact_list::AddContact(const contact& newContact, size_t MAX, size_t& t) char City[35]; char State[4]; int Zip = 0; - newContact[i].Set_a(0); - newContact[i].Set_id(i+1); + contact.Set_a(0); + contact.Set_id(i + 1); //newContact[i].count = t; cin.ignore(1000, '\n'); cout << "Please enter each piece of information when you are prompted to" << endl; cout << "enter first name: " << endl; cin >> firstName; - newContact[i].Set_firstName(firstName); + contact.Set_firstName(firstName); cout << "enter last name: " << endl; cin >> lastName; - newContact[i].Set_lastName(lastName); + contact.Set_lastName(lastName); cout << "enter Email: " << endl; cin >> Email; - newContact[i].Set_email(Email); + contact.Set_email(Email); cout << "enter Street Address: " << endl; cin >> StreetAddress; - newContact[i].Set_streetAddress(StreetAddress); + contact.Set_streetAddress(StreetAddress); cout << "enter city: " << endl; cin >> City; - newContact[i].Set_city(City); + contact.Set_city(City); cout << "enter State as two letter abbreviation: " << endl; cin >> State; - newContact[i].Set_state(State); + contact.Set_state(State); cout << "Please enter the next value as a series of numbers" << endl; cout << "enter Zip: " << endl; cin >> Zip; - newContact[i].Set_zip(Zip); + contact.Set_zip(Zip); t++; break; } - + //cout << newContact[i]->Name << "\n" << newContact[i]->Email << "\n" << newContact[i]->StreetAddress << "\n" << newContact[i]->City << "\n" << newContact[i]->State << "\n" << newContact[i]->Zip << endl; - -} -// important below. may need if current testing doesnt work. -//void contact_list::AddContact(const contact& contact) -//{ -// size_t length = contact_list::length_; -// for (size_t i = 0; i < length, i++;) -// { -// -// } -// -//} +} void contact_list::Update(contact newContact, size_t MAX) { @@ -462,4 +465,6 @@ void contact_list::DeleteContact(contact newContact[], size_t MAX) void contact_list::CopyList(const contact* contacts, const size_t& size) { -}
\ No newline at end of file +} + + |