diff options
| author | Connor McDowell <[email protected]> | 2024-03-03 17:21:44 -0800 |
|---|---|---|
| committer | Connor McDowell <[email protected]> | 2024-03-03 17:21:44 -0800 |
| commit | a691340fbba0a08f6382a672aa5652032dff285b (patch) | |
| tree | d21ac7a89b3779e87797b71da2b99b7ed68424aa | |
| parent | print not working. or data not being saved in add new. (diff) | |
| download | homework-7-connormcdowell275-a691340fbba0a08f6382a672aa5652032dff285b.tar.xz homework-7-connormcdowell275-a691340fbba0a08f6382a672aa5652032dff285b.zip | |
OK saving to contact works, moving it into list is not. will work on copy later. error with add contact
| -rw-r--r-- | Project1/Contact_list.h | 1 | ||||
| -rw-r--r-- | Project1/contacts.cpp | 128 | ||||
| -rw-r--r-- | Project1/program.cpp | 54 |
3 files changed, 130 insertions, 53 deletions
diff --git a/Project1/Contact_list.h b/Project1/Contact_list.h index 2338bf7..81dddaf 100644 --- a/Project1/Contact_list.h +++ b/Project1/Contact_list.h @@ -39,5 +39,4 @@ public: }; - #endif CONTACT_LIST_H diff --git a/Project1/contacts.cpp b/Project1/contacts.cpp index 7374fdf..d90f003 100644 --- a/Project1/contacts.cpp +++ b/Project1/contacts.cpp @@ -147,9 +147,53 @@ void contact::print() } //functions -void contact_list::AddContact(const contact& contact) +void addContact(contact newContact, size_t MAX, contact_list contacts[]) { - contacts_[size_++] = contact; + for(auto i = 0u; i < MAX; ++i) + { + char firstName[30]; + char lastName[30]; + char Email[105]; + char StreetAddress[45]; + char City[35]; + char State[4]; + int Zip = 0; + newContact.Set_a(0); + newContact.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.Set_firstName(firstName); + cout << "enter last name: " << endl; + cin >> lastName; + newContact.Set_lastName(lastName); + cout << "enter Email: " << endl; + cin >> Email; + newContact.Set_email(Email); + cout << "enter Street Address: " << endl; + cin >> StreetAddress; + newContact.Set_streetAddress(StreetAddress); + cout << "enter city: " << endl; + cin >> City; + newContact.Set_city(City); + cout << "enter State as two letter abbreviation: " << endl; + cin >> State; + newContact.Set_state(State); + cout << "Please enter the next value as a series of numbers" << endl; + cout << "enter Zip: " << endl; + cin >> Zip; + newContact.Set_zip(Zip); + size_t id = i + 1; + newContact.Set_id(id); + break; + } +} + +void contact_list::AddContact(const contact& newContact) +{ + contacts_[size_++] = newContact; //CURRENTLY TESTING //for (size_t i = 0; i < size_, i++;) //{ @@ -201,46 +245,46 @@ void contact_list::AddContact(const contact& contact) // break; // } //} - for (size_t i = 0; i < size_; i++) - { - char firstName[30]; - char lastName[30]; - char Email[105]; - char StreetAddress[45]; - char City[35]; - char State[4]; - int Zip = 0; - contacts_[i].Set_a(0); - contacts_[i].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; - contacts_[i].Set_firstName(firstName); - cout << "enter last name: " << endl; - cin >> lastName; - contacts_[i].Set_lastName(lastName); - cout << "enter Email: " << endl; - cin >> Email; - contacts_[i].Set_email(Email); - cout << "enter Street Address: " << endl; - cin >> StreetAddress; - contacts_[i].Set_streetAddress(StreetAddress); - cout << "enter city: " << endl; - cin >> City; - contacts_[i].Set_city(City); - cout << "enter State as two letter abbreviation: " << endl; - cin >> State; - contacts_[i].Set_state(State); - cout << "Please enter the next value as a series of numbers" << endl; - cout << "enter Zip: " << endl; - cin >> Zip; - contacts_[i].Set_zip(Zip); - size_t id = i + 1; - contacts_[i].Set_id(id); - break; - } + //for (size_t i = 0; i < size_; i++) + //{ + // char firstName[30]; + // char lastName[30]; + // char Email[105]; + // char StreetAddress[45]; + // char City[35]; + // char State[4]; + // int Zip = 0; + // contacts_[i].Set_a(0); + // contacts_[i].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; + // contacts_[i].Set_firstName(firstName); + // cout << "enter last name: " << endl; + // cin >> lastName; + // contacts_[i].Set_lastName(lastName); + // cout << "enter Email: " << endl; + // cin >> Email; + // contacts_[i].Set_email(Email); + // cout << "enter Street Address: " << endl; + // cin >> StreetAddress; + // contacts_[i].Set_streetAddress(StreetAddress); + // cout << "enter city: " << endl; + // cin >> City; + // contacts_[i].Set_city(City); + // cout << "enter State as two letter abbreviation: " << endl; + // cin >> State; + // contacts_[i].Set_state(State); + // cout << "Please enter the next value as a series of numbers" << endl; + // cout << "enter Zip: " << endl; + // cin >> Zip; + // contacts_[i].Set_zip(Zip); + // size_t id = i + 1; + // contacts_[i].Set_id(id); + // 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; diff --git a/Project1/program.cpp b/Project1/program.cpp index 4029c61..5b28a17 100644 --- a/Project1/program.cpp +++ b/Project1/program.cpp @@ -22,7 +22,7 @@ int main() contact_list contacts(MAX); size_t t = 0; - contacts.set_size(sizeof(newContact)); + contacts.set_size(MAX); while (O == 1) { //cout << MAX << endl; @@ -39,16 +39,50 @@ int main() { case 1: //addNew(newContact, MAX, t); + //contacts.AddContact(newContact); + //addContact(newContact, contacts.get_size(), contacts[MAX]); + for (auto i = 0u; i < MAX; ++i) + { + char firstName[30]; + char lastName[30]; + char Email[105]; + char StreetAddress[45]; + char City[35]; + char State[4]; + int Zip = 0; + newContact.Set_a(0); + newContact.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.Set_firstName(firstName); + cout << "enter last name: " << endl; + cin >> lastName; + newContact.Set_lastName(lastName); + cout << "enter Email: " << endl; + cin >> Email; + newContact.Set_email(Email); + cout << "enter Street Address: " << endl; + cin >> StreetAddress; + newContact.Set_streetAddress(StreetAddress); + cout << "enter city: " << endl; + cin >> City; + newContact.Set_city(City); + cout << "enter State as two letter abbreviation: " << endl; + cin >> State; + newContact.Set_state(State); + cout << "Please enter the next value as a series of numbers" << endl; + cout << "enter Zip: " << endl; + cin >> Zip; + newContact.Set_zip(Zip); + size_t id = i + 1; + newContact.Set_id(id); + newContact.print(); + break; + } contacts.AddContact(newContact); - //if (t >= MAX) // Check if the number of contacts exceeds MAX - //{ - // contact* newContactTemp = new contact[MAX * 2]; // Double the size - // for (size_t i = 0; i < MAX; ++i) // Copy existing contacts - // newContactTemp[i] = newContact[i]; - // delete[] newContact; // Deallocate old memory - // newContact = newContactTemp; // Update pointer - // MAX *= 2; // Update MAX - //} break; case 2: //contacts.Update(newContact); |