aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor McDowell <[email protected]>2024-02-19 20:42:12 -0800
committerConnor McDowell <[email protected]>2024-02-19 20:42:12 -0800
commit940701c948ba488c0d2ae7e7214763001d4b5684 (patch)
tree4a58c655da6989bbbdd3c2f94346d80487f6eb16
parentstarted fuckin over. (diff)
downloadhomework-6-connormcdowell275-940701c948ba488c0d2ae7e7214763001d4b5684.tar.xz
homework-6-connormcdowell275-940701c948ba488c0d2ae7e7214763001d4b5684.zip
i hate this. with this combined with assignment 5 ive spent almost 30 hours over two days plus the last 4 hours on this.
-rw-r--r--Project1/Contacts.h2
-rw-r--r--Project1/contacts.cpp20
-rw-r--r--Project1/program.cpp15
3 files changed, 23 insertions, 14 deletions
diff --git a/Project1/Contacts.h b/Project1/Contacts.h
index edeb2e0..440f06a 100644
--- a/Project1/Contacts.h
+++ b/Project1/Contacts.h
@@ -28,6 +28,6 @@ void update(contact newContact[], size_t MAX);
void printAll(contact newContact[], size_t MAX);
-void contact_double(contact*& newContact, size_t MAX, size_t t);
+contact 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 dd7f0e8..b21f971 100644
--- a/Project1/contacts.cpp
+++ b/Project1/contacts.cpp
@@ -57,7 +57,7 @@ char addNew(contact newContact[], size_t MAX, size_t t)
// state
// zip
-void update(struct contact newContact[], size_t MAX)
+void update(contact newContact[], size_t MAX)
{
cout << "select a contact to update based on their position in the list (check print all contacts for list position)" << endl;
int c = 0;
@@ -87,20 +87,20 @@ void update(struct contact newContact[], size_t MAX)
void printAll(contact newContact[], size_t MAX)
{
- for (size_t i = 0; i < MAX; ++i)
+ for (int i = 0; i < MAX; ++i)
{
/*for (int t = -1; t < newContact[i].id;) {
break;
}*/
- /*if (newContact[i].id == 0) {
+ if (newContact[i].id == 0) {
break;
- }*/
+ }
if (newContact[i].id < 0) {
break;
}
- //if (newContact[i].id > Cont_list_lenth) {
- // break;
- //}
+ if (newContact[i].id > MAX) {
+ break;
+ }
cout << "List number: " << newContact[i].id << endl;
cout << "name: " << newContact[i].Name << endl;
@@ -112,14 +112,16 @@ void printAll(contact newContact[], size_t MAX)
}
}
-void contact_double(contact*& newContact, size_t MAX, size_t t)
+contact contact_double(contact newContact[], size_t MAX, size_t t)
{
contact* doubleContact = new contact[MAX * 2];
- for (newContact[t].count = t; t < MAX * 2;)
+ for (newContact[t].count = t; t < MAX * 2; ++t)
{
doubleContact[t] = newContact[t];
}
+ MAX = MAX * 2;
delete[] newContact;
newContact = doubleContact;
+ return newContact[MAX];
} \ No newline at end of file
diff --git a/Project1/program.cpp b/Project1/program.cpp
index 7f01a8f..639a7ac 100644
--- a/Project1/program.cpp
+++ b/Project1/program.cpp
@@ -14,10 +14,10 @@ using std::endl;
int main()
{
- constexpr size_t MAX = 10;
+ size_t MAX = 3;
int O = 1;
- int t = 0;
- contact newContact[MAX];
+ size_t t = 0;
+ contact* newContact = new contact[MAX];
while (O == 1)
{
int c = 0;
@@ -32,7 +32,6 @@ int main()
if (c == 1)
{
addNew(&newContact[MAX], MAX, t);
- ++t;
//cout << t << endl;
}
if (c == 2)
@@ -46,6 +45,14 @@ int main()
if (c == 5)
{
O = 0;
+ delete[] newContact;
+ }
+ ++t;
+ if (t >= MAX - 1)
+ {
+ *newContact = contact_double(&newContact[MAX], MAX, t);
+ MAX = MAX * 2;
}
}
+ return 0;
} \ No newline at end of file