Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem: Write a C++ program that will implement and test the five functions described below that use pointers and dynamic memory allocation. The Functions: You

image text in transcribed
image text in transcribed
image text in transcribed
Problem: Write a C++ program that will implement and test the five functions described below that use pointers and dynamic memory allocation. The Functions: You will write the five functions described below. Then you will call them from the main function, to demonstrate their correctness 1. minimum: takes an int array and the array's size as arguments. It should return the minimum value of the array elements. Do not use square brackets anywhere in the function, not even the parameter list (use pointers instead). 2. swapTimesTen: The following function uses reference parameters. Rewrite the function so it uses pointers instead of reference variables. When you test this function from the main program, demonstrate that it changes the values of the variables passed into it. int swapTimesTen (int &x, int &y) int temp = x; xy10; y temp10; return x + y; 3. doubleArray: 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 first half of the new array, and the contents of the argument array each multiplied by 2 to the second half of the new array. The function should return a pointer to the new array. 4. subArray: takes an int array, a start index and a length as arguments. It creates a new array that is a copy of the elements from the original array starting at the start index, and has length equal to the length argument. For example, subArray(aa,5,4) would return a new array containing only the elements aa[5], aa[6, aa7, and aa8]. The function should return a pointer to the new array. Do not call any other functions from this function. Hint: modify the code from duplicateArray 5. subArray2: takes an int array, a start index and a length as arguments. It behaves exactly like subArray, however, you must define subArray2 as follows: Add the code for the definition of the duplicateArray function from the lecture slides for Unit 3 (or from the textbook) to your program. Add the code for the subArray2 function given below to your program. Fill in the blanks with expressions so that the function subArray2 behaves as the first subArray. int *subArray2 (int *array, int start, int ength) int *result return result duplicateArray (. DO NOT alter duplicateArray, DO NOT alter subArray2 as defined above. Output: Test these five functions using the main function as a driver. The driver should pass constant test data as arguments to the functions. Select appropriate test data for each function and then call that function using the test data. For each function, you should output four lines: a label indicating which function is being tested, the test data, the expected results, and the actual results. For the test data and Expected result, you should hard code the output values (use string literals containing the numeric values), for the Actual results, use the actual values returned/altered by the function. testing minimum: test data: 1 2 3 4 5 6 7-8 9 0 Expected minimum: -8 Actual minimum: 8 test data: 1 2 3 4 5 16 7 89 0 Expected minimum: 0 Actual minimum: 0 testing swapTimesTen Expected result: 80 a: 50 b: 30 Actual results 80 a: 50 b: 30

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

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions