aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor McDowell <[email protected]>2024-02-15 16:52:41 -0800
committerConnor McDowell <[email protected]>2024-02-15 16:52:41 -0800
commitac9e104567f6989d9959d9cf16019adb926a59c2 (patch)
tree75ed3932ea80352c5fe437580bf698b42aa07c5e
parentlinks created, usings created (diff)
downloadin-class-exercise-12-connormcdowell275-ac9e104567f6989d9959d9cf16019adb926a59c2.tar.xz
in-class-exercise-12-connormcdowell275-ac9e104567f6989d9959d9cf16019adb926a59c2.zip
print and double created
-rw-r--r--Project1/c_array.cpp25
-rw-r--r--Project1/c_array.h2
-rw-r--r--Project1/main.cpp7
3 files changed, 34 insertions, 0 deletions
diff --git a/Project1/c_array.cpp b/Project1/c_array.cpp
index fd64a39..f504839 100644
--- a/Project1/c_array.cpp
+++ b/Project1/c_array.cpp
@@ -7,3 +7,28 @@ using std::cout;
using std::endl;
+void DoubleArraySize(int*& array, size_t size)
+{
+ int* newArray = nullptr;
+
+ newArray = new int[size * 2];
+
+ for (auto i = 0u; i < size; ++i)
+ {
+ newArray[i] = array[i];
+ }
+ delete[] array;
+
+ array = newArray;
+
+ size *= 2;
+}
+
+void PrintArray(int* array, size_t size)
+{
+ for (auto i = 0u; i < size; i++)
+ {
+ cout << "array[" << i << "] = " << array[i] << endl;
+ }
+ cout << endl;
+} \ No newline at end of file
diff --git a/Project1/c_array.h b/Project1/c_array.h
index 95a13d4..e4cca9f 100644
--- a/Project1/c_array.h
+++ b/Project1/c_array.h
@@ -1,7 +1,9 @@
#ifndef C_ARRAY_HEADER
#define C_ARRAY_HEADER
+void DoubleArraySize(int*& array, size_t size);
+void PrintArray(int* array, size_t size);
#endif C_ARRAY_HEADER
diff --git a/Project1/main.cpp b/Project1/main.cpp
index dab64a4..5dd3c7c 100644
--- a/Project1/main.cpp
+++ b/Project1/main.cpp
@@ -13,8 +13,15 @@ using std::endl;
int main()
{
+ constexpr size_t SIZE = 101;
+ int* array = new int[SIZE];
+ PrintArray(array, SIZE);
+ DoubleArraySize(array, SIZE);
+ PrintArray(array, SIZE);
+
+ delete[] array;
return 0;
} \ No newline at end of file