diff options
| author | Connor McDowell <[email protected]> | 2024-02-29 16:02:20 -0800 |
|---|---|---|
| committer | Connor McDowell <[email protected]> | 2024-02-29 16:02:20 -0800 |
| commit | 903d582231befeccae18be5af3b23ee92235d343 (patch) | |
| tree | 33a5b78025e856d18480df35a90cae6ce4cac88e /Project1 | |
| parent | list of contacts created (diff) | |
| download | homework-7-connormcdowell275-903d582231befeccae18be5af3b23ee92235d343.tar.xz homework-7-connormcdowell275-903d582231befeccae18be5af3b23ee92235d343.zip | |
refactoring add new.
Diffstat (limited to 'Project1')
| -rw-r--r-- | Project1/Contacts.h | 8 | ||||
| -rw-r--r-- | Project1/contacts.cpp | 71 | ||||
| -rw-r--r-- | Project1/program.cpp | 8 |
3 files changed, 57 insertions, 30 deletions
diff --git a/Project1/Contacts.h b/Project1/Contacts.h index d485659..db2de53 100644 --- a/Project1/Contacts.h +++ b/Project1/Contacts.h @@ -40,9 +40,17 @@ public: const char* Get_email(); void Set_email(const char* email); + size_t Get_a(); + void Set_a(size_t a); + + size_t Get_id(); + void Set_id(size_t id); + void print(); private: + size_t _a = 0; + // _a functions as delete bool. if a = 1, the slot is overwritten int _id; const char* _firstName{ }; const char* _lastName{ }; diff --git a/Project1/contacts.cpp b/Project1/contacts.cpp index 6462a52..c393b8e 100644 --- a/Project1/contacts.cpp +++ b/Project1/contacts.cpp @@ -13,7 +13,6 @@ void contact::Set_firstName(const char* firstName) { _firstName = firstName; } - const char* contact::Get_firstName() { return _firstName; @@ -23,7 +22,6 @@ void contact::Set_lastName(const char* lastName) { _lastName = lastName; } - const char* contact::Get_lastName() { return _lastName; @@ -33,7 +31,6 @@ void contact::Set_streetAddress(const char* streetAddress) { _streetAddress = streetAddress; } - const char* contact::Get_streetAddress() { return _streetAddress; @@ -43,7 +40,6 @@ void contact::Set_city(const char* city) { _city = city; } - const char* contact::Get_city() { return _city; @@ -53,7 +49,6 @@ void contact::Set_state(const char* state) { _state = state; } - const char* contact::Get_state() { return _state; @@ -63,7 +58,6 @@ void contact::Set_zip(int zip) { _zip = zip; } - int contact::Get_zip() { return _zip; @@ -73,7 +67,6 @@ void contact::Set_email(const char* email) { _email = email; } - const char* contact::Get_email() { return _email; @@ -83,7 +76,6 @@ void contact_list::set_length(size_t MAX) { length_ = MAX; } - size_t contact_list::get_length() { return length_; @@ -93,7 +85,6 @@ void contact_list::set_size(size_t size) { size_ = size; } - size_t contact_list::get_size() { return size_; @@ -103,14 +94,28 @@ void contact::Set_index(int id) { _id = id; } - int contact::Get_index() { return _id; } +void contact::Set_a(size_t a) +{ + _a = a; +} +size_t contact::Get_a() +{ + return _a; +} - +void contact::Set_id(size_t id) +{ + _id = id; +} +size_t contact::Get_id() +{ + return _id; +} //functions char addNew(contact newContact[], size_t MAX, size_t& t) @@ -126,33 +131,51 @@ char addNew(contact newContact[], size_t MAX, size_t& t) //CURRENTLY WORKS for (size_t i = 0; i < MAX, i++;) { - for(newContact[i].a = 1; ++i;) + int a = newContact[i].Get_a(); + for(a = 1; ++i;) { - newContact[i].a = 0; - for (auto j = newContact[i].id; j < MAX; j++) + newContact[i].Set_a(0); + int temp = newContact[i].Get_id(); + for (auto j = temp; j < MAX; j++) { - if(newContact[i].id != 0) + if(newContact[i].Get_id() != 0) { i = i + 1; } } - newContact[i].id = i; - newContact[i].count = t; + char firstName[30]; + char lastName[30]; + char Email[105]; + char StreetAddress[45]; + char City[35]; + char State[4]; + int Zip = 0; + newContact[i].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 name: " << endl; - cin.getline(newContact[i].Name, 25); + cout << "enter first name: " << endl; + cin >> firstName; + newContact[i].Set_firstName(firstName); + cout << "enter last name: " << endl; + cin >> lastName; + newContact[i].Set_lastName(lastName); cout << "enter Email: " << endl; - cin.getline(newContact[i].Email, 100); + cin >> Email; + newContact[i].Set_email(Email); cout << "enter Street Address: " << endl; - cin.getline(newContact[i].StreetAddress, 35); + cin >> StreetAddress; + newContact[i].Set_streetAddress(StreetAddress); cout << "enter city: " << endl; - cin.getline(newContact[i].City, 30); + cin >> City; + newContact[i].Set_city(City); cout << "enter State as two letter abbreviation: " << endl; - cin.getline(newContact[i].State, 3); + cin >> State; + newContact[i].Set_state(State); cout << "Please enter the next value as a series of numbers" << endl; cout << "enter Zip: " << endl; - cin >> newContact[i].Zip; + cin >> Zip; + newContact[i].Set_zip(Zip); break; } } diff --git a/Project1/program.cpp b/Project1/program.cpp index d8bcec1..129284f 100644 --- a/Project1/program.cpp +++ b/Project1/program.cpp @@ -17,15 +17,11 @@ int main() size_t MAX = 3; int O = 1; /* t = index counter*/ - contact newContact; + contact* newContact = new contact[MAX]; contact_list contact_list; - size_t length = contact_list.get_length(); - contact contactArray[length] = { newContact }; + size_t t = 0; - //contact* newContact = new contact[MAX]; - //int length = sizeof(newContact[MAX]); int size = sizeof(newContact); - //cout << sizeof(newContact[MAX]) << endl; while (O == 1) { //cout << MAX << endl; |