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.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

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;
Transcribed Image Text: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;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY