Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

  1. 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.

  2. 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.

image text in transcribed

5.3: Dynamic Array > src > C main.c > maino 1 #include 2 #include 3 #include "source.h" 4 5 void printarray(const int *array, int size) { 6 printf("{ "); 7 for (int i = 0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions

Question

What tasks are aided by a work sheet?

Answered: 1 week ago