csci 20 :: book learning challenge 12 (due tues, apr 19)
Submitting your work: Complete this exercise on your own.

Fill in all of the "Answer" boxes, then print the answer grid that you see after you press "Prepare for printing".

Staple all pages together and submit to the instructor on the date listed above.

Questions:

Download this code when answering the questions on today's challenge.

READ: C++ Passing arrays to functions , Return array from functions in C++ then answer the following:

Your name:
  1. Does C++ allow you to pass an entire array as an argument to a function? If not, does C++ have a mechanism to access array data inside of a function?
    Answer:
  2. Your reading presents three different ways of passing pointers to arrays into functions. Write the code (using "Way-1") for a function named printArray that does the following -- in your answer, make note of any limitations or difficulties of this way of passing an array pointer:
    1. returns void
    2. contains a parameter numbers that is a pointer to an int array
    3. loops through the array numbers and prints each value in the array, one value per line

    Answer:
  3. Your reading presents three different ways of passing pointers to arrays into functions. Write the code (using "Way-2") for a function named printArray that does the following -- in your answer, make note of any limitations or difficulties of this way of passing an array pointer:
    1. returns void
    2. contains a parameter numbers that is a pointer to an int array of size ten (10)
    3. loops through the array numbers and prints each value in the array, one value per line

    Answer:
  4. Your reading presents three different ways of passing pointers to arrays into functions. Write the code (using "Way-3") for a function named printArray that does the following -- in your answer, make note of any limitations or difficulties of this way of passing an array pointer:
    1. returns void
    2. contains a parameter numbers that is a pointer to an int array
    3. loops through the array numbers and prints each value in the array, one value per line

    Answer:
  5. Write the code (this is the "best way" that will be introduced by the instructor) for a function named printArray that does the following -- in your answer, make note of why this is a desirable way to write functions that operate on arrays:
    1. returns void
    2. contains a parameter numbers that is a pointer to an int array
    3. contains a parameter size that is an int
    4. loops through the array numbers and prints each value in the array, one value per line

    Answer:
  6. Write the C++ code that you would add to this code to do the following:
    • use machineOne.buildArray to create a dynamic integer array of size five (5)
    • assign the array returned by buildArray to the variable valuesOne
    • use machineOne.buildArray to create a dynamic integer array of size ten (10)
    • assign the array returned by buildArray to the variable valuesTwo

    Answer:
  7. Write the C++ code that you would add to this code to do the following:
    • use machineOne.initializeArray to set all initial values in valuesOne to 1
    • use machineOne.initializeArray to set all initial values in valuesTwo to -1

    Answer:
  8. Write the C++ code that you would add to this code to do the following, and show the output of each below:
    • use machineOne.printArray to display valuesOne
    • use machineOne.printArray to display valuesTwo

    Answer:
  9. Write the C++ code that you would add to this code to do the following:
    • use machineOne.adjustArray to increase by 1 each of the values in valuesOne
    • use machineOne.adjustArray to decrease by 1 each of the values in valuesTwo

    Answer:
  10. Write the C++ code that you would add to this code to do the following, and show the output of each below:
    • use machineOne.printArray to display valuesOne
    • use machineOne.printArray to display valuesTwo

    Answer:
  11. Write the C++ code that you would add to this code to do the following:
    • release/free the memory associated with valuesOne
    • release/free the memory associated with valuesTwo

    Answer:

Total points for this book learning challenge:

150 points