aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor McDowell <[email protected]>2024-02-19 16:57:46 -0800
committerConnor McDowell <[email protected]>2024-02-19 16:57:46 -0800
commit2b40c135bdbda403394d4970d8eee44532a3dc0d (patch)
tree9b0187b4cf4ba1223cb3b43a40ca3b1d6f136c22
parent.cpps and .hs added (diff)
downloadhomework-6-connormcdowell275-2b40c135bdbda403394d4970d8eee44532a3dc0d.tar.xz
homework-6-connormcdowell275-2b40c135bdbda403394d4970d8eee44532a3dc0d.zip
working on doubling the size
-rw-r--r--Project1/Contacts.h2
-rw-r--r--Project1/contacts.cpp14
-rw-r--r--Project1/program.cpp33
3 files changed, 32 insertions, 17 deletions
diff --git a/Project1/Contacts.h b/Project1/Contacts.h
index a7d5dda..923c404 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);
-
+//char contact_double(contact*& newContact, size_t MAX, int t);
#endif CONTACTS_HEADER_H \ No newline at end of file
diff --git a/Project1/contacts.cpp b/Project1/contacts.cpp
index 573a8a7..5925152 100644
--- a/Project1/contacts.cpp
+++ b/Project1/contacts.cpp
@@ -28,6 +28,7 @@ char addNew(contact newContact[], size_t MAX, int t)
{
cout << "Please enter all inputs as english characters with underscores (_) for spaces" << endl;
newContact[i].id = i + 1;
+ newContact[i].count = t;
cout << "enter name: " << endl;
cin >> newContact[i].Name;
cout << "enter Email: " << endl;
@@ -108,3 +109,16 @@ void printAll(contact newContact[], size_t MAX)
cout << "Zip: " << newContact[i].Zip << endl;
}
}
+
+//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
diff --git a/Project1/program.cpp b/Project1/program.cpp
index 4e62543..6bf362d 100644
--- a/Project1/program.cpp
+++ b/Project1/program.cpp
@@ -10,25 +10,12 @@ using std::cin;
using std::cout;
using std::endl;
-
-//
-//
-//int main()
-//{
-//
-//
-//
-//
-//
-// return 0;
-//}
-
int main()
{
- constexpr size_t MAX = 10;
+ size_t MAX = 3;
int O = 1;
int t = 0;
- contact newContact[MAX];
+ contact* newContact = new contact[MAX];
while (O == 1)
{
int c = 0;
@@ -43,7 +30,21 @@ int main()
{
addNew(&newContact[MAX], MAX, t);
++t;
- //cout << t << endl;
+ cout << t << endl;
+ cout << "enter full length of array" << endl;
+ cin >> t;
+ if (t >= 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;
+ }
}
if (c == 2)
{