Question
Programming task 5.3: Dynamic Array (30 pts) // t his is a c++ course In this task, we practice dynamic memory allocation and extending arrays
Programming task 5.3: Dynamic Array (30 pts) // this is a c++ course
In this task, we practice dynamic memory allocation and extending arrays
Two functions need to be implemented in this task. To collect points, some kind of implementation must exist for both functions. Remember, valgrind errors must not be present to get full points.
-
Implement function int *create_dyn_array(unsigned int n) that allocates an int array for n integers. n is given as argument to the function when it is called. After allocating the array, the function should read the given number of integers to the array from user, using the scanf function. After the right amount of integers have been read, the function returns pointer to the dynamically allocated array.
-
Implement function int *add_dyn_array(int *arr, unsigned int num, int newval) that adds a single integer to the existing dynamically allocated array of integers (arr). The length of the existing array is num, and the new integer to be added is given in parameter newval. Youll need to ensure that array is extended to hold the additional integer. Check that the function works correctly when called several consecutive times.
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