Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program that will test function described below that use pointers and dynamic memory allocation. Functions: You will write the function described below.

Write a C++ program that will test function described below that use pointers and dynamic memory allocation.

Functions:

You will write the function described below. Then you will call them from the main function, to demonstrate their correctness.

grow_array: takes an int array and the array's size as arguments. It should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array, and initialize the unused elements of the new array with -1. The function should return a pointer to the new array.

array will be {1,2,3,4,5,6,7,8,9,0}. User do not have to put any values.

out put:

testing expand: Expected result: 1 2 3 4 5 6 7 8 9 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

Actualresult: 1 2 3 4 5 6 7 8 9 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

RULES:

  • DO NOT change the names of the functions!

  • DO NOT do any output from the functions (only from main)!

  • DO NOT do any input at all!

    NOTES:

  • This program DOES need to be done in a Linux or Unix environment.

  • It is your responsibility to fully test your functions. They must work for ANY valid input. The main function you submit must have at least one test case for each function. However, you should test the functions over several different test cases to convince yourself that they work.

  • You do not need to use named constants for your test data (or array sizes) in this assignment, but you DO need to follow the rest of the style guidelines including function definition and comments.

  • Your program should release any dynamically allocated memory when it is finished using it.

  • you may want to include a function that displays the values of an int array on one line, separated by spaces, for displaying test arrays and results.

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

From Herds To Insights Harnessing Data Analytics For Sustainable Livestock Farming

Authors: Prof Suresh Neethirajan

1st Edition

B0CFD6K6KK, 979-8857075487

More Books

Students also viewed these Databases questions