
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;
}
![Main:
Output Example:
int main( ) {
Enter a size: 5
cout << endl;
Original:
int size, newsize;
0 12 3 4
cout << "Enter a size: ";
Ox7f970bd04080
cin >> size;
Ox7f970bd04084
Ox7f970bd04088
cout << endl;
Ox7f970bd0408c
int +p = new int [size]):
cout << "Original: " << endl;
Ox7f970bd04090
populate(p, size);
print(p, size);
printMenory(p, size);
Enter a new size:
cout << endl;
Inside grow:
0 1 2
Ox7f970bd040a0
cout << "Enter a new size: ";
cin >> newSize;
Ox7f970bd040a4
Ox7f970bd040a8
cout « endl;
p = grow(p, size, newsize);
cout <« "After grow:
print(p, newSize);
printMenory(p, newSize);
« endl;
After grow:
0 1 2
Ox7f970bd040a0
cout << endl;
Ox7f970bd040a4
Ox7f970bd040a8
return e;](https://content.bartleby.com/qna-images/question/86bfc21f-7304-4d6a-8ae3-de059a5180e7/1d447373-9dee-48ee-9d1c-3efe35d10c17/tjgfa3_thumbnail.png)

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 3 images

- need help c++ Write the specified code: 1. Initialize an dynamic integer array of size 5 with the values 1,2,3,4,5. 2. Use pointer arithmetic to swap the 2nd and 4th values in the array. 3. Use a loop and pointer arithmetic to print all array values. PLEASE USE POINTER ARTHIMETIC IN YOUR CODEarrow_forwardI'm stuck on this question and I don't know how I should be approaching this. What should I do?arrow_forwardIn C++, Can you please look at the code below and revise/fix so it will work according to instructions and criteria. Instruction 1) Write a function that copies a 1D array to a 2D array. The function’s prototype is bool copy1DTo2D(int d1[], int size, int d2[][NCOLS], int nrows); where size > 0 NCOLS > 0 nrows > 0 NCOLS is a global constant size = NCOLS * nrows the function returns true if the parameters and constants satisfy these conditions and false otherwise. the relation between 1d array indices and 2d array indices is 2d row index = 1d array index / NCOLS 2d column index = 1d array index modulus operator NCOLS 2) Write a function that copies a 2D array to a 1D array. The function’s prototype is bool copy2DTo1D(int d2[][NCOLS, int nrows, int d1[], int size); where size > 0 NCOLS > 0 nrows > 0 NCOLS is a global constant the function return true if the parameters and constants satisfy these conditions and false otherwise. the relation between 1d array indices and…arrow_forward
- MIPS Assembly The program: Write a function in MIPS assembly that takes an array of integers and finds local minimum points. i.e., points that if the input entry is smaller than both adjacent entries. The output is an array of the same size of the input array. The output point is 1 if the corresponding input entry is a relative minimum, otherwise 0. (You should ignore the output array's boundary items, set to 0.) My code: # (Note: The first/last entry of the output array is always 0# since it's ignored, never be a local minimum.)# $a0: The base address of the input array# $a1: The base address of the output array with local minimum points# $a2: Size of arrayfind_local_minima:############################ Part 2: your code begins here ###la $t1, ($t2)la $t1, ($t2)move $a1, $s0 li $a2, 4jal find_local_minima print:ble $a2, 0, exitlw $a0, ($s0)li $v0, 1syscall addi $s0, $s0, 4addi $a2, $a2, -1 ############################ Part 2: your code ends here ###jr $ra I am not getting the correct…arrow_forward1-Write python code that implements an indexed array and an associative array (dictionary). 2- Use examples to explain the two main problems with Pointers 3- What is the output of the following Python code: x=3 y="5" print (x+y)arrow_forwardC+++ Coding I need help wtih Pointer Basics Please see attached.arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





