From f03cc9b2c36a355f07708c9098c60e3eb586abf5 Mon Sep 17 00:00:00 2001 From: Connor McDowell Date: Tue, 5 Mar 2024 18:01:06 -0800 Subject: print still not working but list creation fixed. previously unseen bug: not incrimenting index positions to save data, would lead to overwriting inputs. fixed by using previous version instance of variable "t" or an index counter located outside of the class. --- Project1/contacts.cpp | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'Project1/contacts.cpp') diff --git a/Project1/contacts.cpp b/Project1/contacts.cpp index 0d8723c..a7def13 100644 --- a/Project1/contacts.cpp +++ b/Project1/contacts.cpp @@ -190,7 +190,7 @@ void addContact(contact newContact, size_t MAX, contact_list contacts[]) } } -void contact_list::AddContact(contact& Contact) +void contact_list::AddContact(contact& Contact, size_t& t) { //CURRENTLY TESTING for (size_t i = 0; i < size_, i++;) @@ -240,21 +240,21 @@ void contact_list::AddContact(contact& Contact) cout << "enter Zip: " << endl; cin >> Zip; contacts_[i].Set_zip(Zip); - //contacts_[size_++] = Contact; + contacts_[size_++] = Contact; break; } } - for (size_t i = 0; i < size_; i++) + for (size_t i = t; i < size_; i++) { - char firstName[30]; - char lastName[30]; - char Email[105]; - char StreetAddress[45]; - char City[35]; - char State[4]; + 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); + contacts_[i].Set_id(i); //newContact[i].count = t; cin.ignore(1000, '\n'); cout << "Please enter each piece of information when you are prompted to" << endl; @@ -280,8 +280,9 @@ void contact_list::AddContact(contact& Contact) cout << "enter Zip: " << endl; cin >> Zip; contacts_[i].Set_zip(Zip); - size_t id = i + 1; - contacts_[i].Set_id(id); + t++; +/* size_t id = i; + contacts_[i].Set_id(id);*/ //contacts_[size_++] = Contact; break; } @@ -347,7 +348,7 @@ void contact_list::Print() const size_t check = contacts_[i].Get_a(); - if (contacts_[i].Get_id() == check) + /*if (contacts_[i].Get_id() == check) { i = i + 1; } @@ -360,7 +361,14 @@ void contact_list::Print() const if (contacts_[i].Get_id() > size_) { break; } - contacts_[i].print(); + cout << "Contact number: " << contacts_[i].Get_id() << endl; + cout << "Full name: " << contacts_[i].Get_firstName() << " " << contacts_[i].Get_lastName() << endl; + cout << "Email: " << contacts_[i].Get_email() << endl; + cout << "Street Address: " << contacts_[i].Get_streetAddress() << endl; + cout << "City: " << contacts_[i].Get_city() << endl; + cout << "State: " << contacts_[i].Get_state() << endl; + cout << "Zip code: " << contacts_[i].Get_zip() << endl; + } } -- cgit v1.2.3