Hello, I am having trouble with my c++ homework. Implement and grow a dynamic array using pointer arithmetic. a) Use the provided main function (see below). b) Implement a populate function which stores values from 0 to size into the array p using pointer arithmetic to access array locations. c) Implement a print function which prints the values of the array p using pointer arithmetic. d) Implement a printMemory function which prints the memory addresses of all elements in array p using pointer arithmetic. e) Implement a grow function which resizes the existing array from the initial size to a new size using pointer arithmetic. f) Verify via the output that the new array is a distinct memory space from the original array.
Hello, I am having trouble with my c++ homework.
Implement and grow a dynamic array using pointer arithmetic.
a) Use the provided main function (see below).
b) Implement a populate function which stores values from 0 to size into the array p using pointer arithmetic to access array locations.
c) Implement a print function which prints the values of the array p using pointer arithmetic.
d) Implement a printMemory function which prints the memory addresses of all elements in array p using pointer arithmetic.
e) Implement a grow function which resizes the existing array from the initial size to a new size using pointer arithmetic.
f) Verify via the output that the new array is a distinct memory space from the original array.
Main: Output Example:
Use the following main function to test your program. (cannot change the int main provided)
int main( ) {
cout << endl;
int size, newSize;
cout << "Enter a size: ";
cin >> size;
cout << endl;
int *p = new int[size]();
cout << "Original: " << endl;
populate(p, size);
print(p, size);
printMemory(p, size);
cout << endl;
cout << "Enter a new size: ";
cin >> newSize;
cout << endl;
p = grow(p, size, newSize);
cout << "After grow: " << endl;
print(p, newSize);
printMemory(p, newSize);
cout << endl;
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images