Problem: Write a C++ program that will implement and test the five functions described below that use pointers...

70.2K

Verified Solution

Question

Programming

Problem:

Write a C++ program that will implement and test the fivefunctions described below

that use pointers and dynamic memory allocation.

The Functions:

You will write the five functions described below. Then you willcall them from the main

function, to demonstrate their correctness.

1. minimum: takes an int array and the array'ssize as arguments. It should

return the minimum value of the array elements. Do notuse square brackets

anywhere in the function, not even the parameter list(use pointers

instead).

2. swapTimesTen: The following function usesreference 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 thevalues of the

variables passed into it.

int swapTimesTen (int &x, int &y)

{

int temp = x;

x = y * 10;

y = temp * 10;

return x + y;

}

3. doubleArray: takes an int array and thearray'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 halfof the new array,

and the contents of the argument array each multiplied by 2 tothe second half

of the new array. The function should return a pointer to thenew array.

!

4. subArray: takes an int array, a start indexand a length as arguments. It

creates a new array that is a copy of theelements from the original array

starting at the start index, and has length equal to the lengthargument. For

example, subArray(aa,5,4) would return a new array containingonly the

elements aa[5], aa[6], aa[7], and aa[8]. The function shouldreturn a pointer to

the new array. Do not call any other functions from thisfunction. Hint: modify

the code from duplicateArray.

5. subArray2: takes an int array, a start indexand a length as arguments. It

behaves exactly like subArray, however, you must definesubArray2 as follows:

Add the code for the definition of the duplicateArray functionfrom the lecture

slides for Unit 3 (or from the textbook) to your program. Addthe code for the

subArray2 function given below to your program. Fill in theblanks with

expressions so that the function subArray2 behaves as the firstsubArray.

int *subArray2 (int *array, int start, int length) {

int *result = duplicateArray(__________, ___________);

return result;

}

DO NOT alter duplicateArray, DO NOT alter subArray2 asdefined above.

Answer & Explanation Solved by verified expert
4.0 Ratings (656 Votes)
int minimumint arr int size int i 0 int min arr    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students