Question
The purpose of this assignment is to help gauge your skills in writing small programs that involve pointers. The program also contains functions and may
The purpose of this assignment is to help gauge your skills in writing small programs that involve pointers. The program also contains functions and may perform input, output, files and file processing, use arrays and vectors and/or c-string/stringarrays, flow of control, and/or calculations.
PROGRAM SPECIFICATION
For this program, we are going toexpand a standard array by dynamically allocating a new one with a larger footprint. The program will use a function that accepts an integer array and the size of the integer array, and then increases it to hold one more item. It shifts all of the original arrays values over by one into the new dynamic array, and sets the first element to the value of zero. When the creation and move are complete, this function returns a (smart) unique pointer pointing to the new dynamic arrayback to the calling program (main).
The program will use the declarations for the array and pointer (in main) as follows:
constint SIZE = 5;
intmyNumbers[SIZE] = {18, 27, 3, 14, 95};
// Define a unique_ptr smart pointer, pointing
// to a dynamically allocated array of integers.
// A unique_ptr is a small, fast, move-only smart
// pointer usually used for managing resources
// with exclusive ownership semantics
unique_ptr
Your program should display 0 18 27 3 14 95 after the element shift function does its work.
The Functions (in separate files):
1.) The first function should dynamically allocate an array to hold the additional element. It should then copyeach element into the new dynamic array.It will return the smart pointer. IMPORTANT: Make sure that yourfunction creates the dynamic array using the unique pointer.
2.) A function to display the elements in the array (called before and after). If you can make this function work for the old and new, bravo. If you need to create two separate functions to print both the old and the new arrays, thats fine. Know that you can get by with just using one.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started