diff options
| author | Connor McDowell <[email protected]> | 2024-02-19 17:59:21 -0800 |
|---|---|---|
| committer | Connor McDowell <[email protected]> | 2024-02-19 17:59:21 -0800 |
| commit | 37e8217e006fc390ea50a65e2c45d8430c535dcb (patch) | |
| tree | 3ca9b1ff441adfd718528788344b73686d134951 | |
| parent | char strings set up (diff) | |
| download | homework-6-connormcdowell275-37e8217e006fc390ea50a65e2c45d8430c535dcb.tar.xz homework-6-connormcdowell275-37e8217e006fc390ea50a65e2c45d8430c535dcb.zip | |
working on doubles
| -rw-r--r-- | Project1/Contacts.h | 6 | ||||
| -rw-r--r-- | Project1/contacts.cpp | 32 | ||||
| -rw-r--r-- | Project1/program.cpp | 34 |
3 files changed, 36 insertions, 36 deletions
diff --git a/Project1/Contacts.h b/Project1/Contacts.h index a6a0691..51f5620 100644 --- a/Project1/Contacts.h +++ b/Project1/Contacts.h @@ -13,7 +13,7 @@ struct contact char Email[100]{}; char StreetAddress[35]{}; char City[30]{}; - char State[5]{}; + char State[3]{}; int Zip = 0; }; @@ -22,12 +22,12 @@ struct contact int menu(); -char addNew(contact newContact[], size_t MAX, int t); +char addNew(contact newContact[], size_t MAX, size_t t); void update(contact newContact[], size_t MAX); void printAll(contact newContact[], size_t MAX); -//char contact_double(contact*& newContact, size_t MAX, int t); +char contact_double(contact*& newContact, size_t MAX, size_t t); #endif CONTACTS_HEADER_H
\ No newline at end of file diff --git a/Project1/contacts.cpp b/Project1/contacts.cpp index 0dcead9..f40e7f2 100644 --- a/Project1/contacts.cpp +++ b/Project1/contacts.cpp @@ -22,12 +22,13 @@ int menu() return c; } -char addNew(contact newContact[], size_t MAX, int t) +char addNew(contact newContact[], size_t MAX, size_t t) { for (int i = t; i < MAX; i++) { newContact[i].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 name: " << endl; cin.getline(newContact[i].Name, 25); @@ -38,7 +39,7 @@ char addNew(contact newContact[], size_t MAX, int t) cout << "enter city: " << endl; cin.getline(newContact[i].City, 30); cout << "enter State as two letter abbreviation: " << endl; - cin.getline(newContact[i].Name, 5); + cin.getline(newContact[i].State, 3); cout << "Please enter the next value as a series of numbers" << endl; cout << "enter Zip: " << endl; cin >> newContact[i].Zip; @@ -64,6 +65,7 @@ void update(struct contact newContact[], size_t MAX) int t = c - 1; for (int i = t; i < MAX;) { + cin.ignore(1000, '\n'); cout << "Please enter each piece of information when you are prompted to" << endl; newContact[i].id = c; cout << "enter name: " << endl; @@ -75,7 +77,7 @@ void update(struct contact newContact[], size_t MAX) cout << "enter city: " << endl; cin.getline(newContact[i].City, 30); cout << "enter State as two letter abbreviation: " << endl; - cin.getline(newContact[i].Name, 5); + cin.getline(newContact[i].State, 3); cout << "Please enter the next value as a series of numbers" << endl; cout << "enter Zip: " << endl; cin >> newContact[i].Zip; @@ -110,15 +112,15 @@ void printAll(contact newContact[], size_t MAX) } } -//char contact_double(contact*& newContact, size_t MAX, int t) -//{ -// contact* doubleContact = new contact[MAX * 2]; -// -// for (newContact[t].count = t; t < MAX * 2;) -// { -// doubleContact[t] = newContact[t]; -// } -// delete[] newContact; -// newContact = doubleContact; -// return newContact; -//}
\ No newline at end of file +char contact_double(contact*& newContact, size_t MAX, size_t t) +{ + contact* doubleContact = new contact[MAX * 2]; + + for (newContact[t].count = t; t < MAX * 2;) + { + doubleContact[t] = newContact[t]; + } + delete[] newContact; + newContact = doubleContact; + +}
\ No newline at end of file diff --git a/Project1/program.cpp b/Project1/program.cpp index 6bf362d..74fce1e 100644 --- a/Project1/program.cpp +++ b/Project1/program.cpp @@ -10,11 +10,12 @@ using std::cin; using std::cout; using std::endl; +constexpr size_t MAX = 3; + int main() { - size_t MAX = 3; int O = 1; - int t = 0; + size_t Cont_list_lenth = 0; contact* newContact = new contact[MAX]; while (O == 1) { @@ -22,29 +23,19 @@ int main() cout << "1. Enter a contact\n"; cout << "2. Update a contact\n"; cout << "3. print all contacts\n"; + cout << "4. Delete a contact\n"; cout << "4. Quit\n"; cout << "\nEnter your choice: " << endl; cin >> c; //c = menu(); if (c == 1) { - addNew(&newContact[MAX], MAX, t); - ++t; - cout << t << endl; - cout << "enter full length of array" << endl; - cin >> t; - if (t >= MAX) + addNew(&newContact[MAX], MAX, Cont_list_lenth); + if (Cont_list_lenth >= MAX) { - contact* doubleContact = new contact[MAX * 2]; - - for (newContact[t].count = t; t < MAX * 2;) - { - doubleContact[t] = newContact[t]; - } - delete[] newContact; - newContact = doubleContact; - MAX = MAX * 2; + contact_double(newContact, MAX, Cont_list_lenth); } + } if (c == 2) { @@ -56,7 +47,14 @@ int main() } if (c == 4) { - O = 0; + //work in progress + } + if (c == 5) + { + delete[] newContact; + return 0; } + ++Cont_list_lenth; + cout << Cont_list_lenth << endl; } }
\ No newline at end of file |