csci 20 :: book learning challenge 11 (due tues, apr 12)
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:

READ: Dynamic memory, C++ Dynamic Memory, Dynamically allocating arrays then answer the following:

Your name:
  1. Write the C++ code to dynamically allocate an array of ten (10) integers using the pointer quantities declared below.
    int* quantities = 0; // 0 is NULL
    Answer:
  2. Write the C++ code to initialize (using a for loop) each of the values in the array quantities -- populate the array with the sequence of values 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 (you must produce these values arithmetically).
    Answer:
  3. Write the C++ code to display (using a for loop) each of the values in the array quantities, one value per line, preceded by its array index. The first line of output, for example, will be:
    index 0: 2
    Answer:
  4. Write the C++ code to (1) free the memory associated with the array quantities and (2) "NULL out" quantities.
    Answer:
  5. Write the C++ code to dynamically allocate an array of five (5) strings using the pointer items declared below.
    string* items = 0; // 0 is NULL
    Answer:
  6. Write the C++ code to populate the array items with the following:
    "hot dogs", "buns", "napkins", "plates", "condiments"
    Answer:
  7. Write the C++ code to display (using a for loop) each of the values in the array items, all on a single line, with quotes and spaces so that your output looks as follows:
    "hot dogs" "buns" "napkins" "plates" "condiments"
    Answer:
  8. Write the C++ code to (1) free the memory associated with the array items and (2) "NULL out" items.
    Answer:
  9. Write the C++ code to (1) declare a dynamic array of bool named flags set to 0 (NULL), (2) dynamically allocate flags to size 100, and (3) set (using a single for loop) every even index (starting with index 0) to true and every odd index to false.
    Answer:
  10. Write the C++ code to (1) count (using count declared below) all of the true values in flags and (2) display the count of true values. Your output should look as follows (replace COUNT with the count your algorithm produces):
    int count = 0;
    True values: COUNT
    Answer:
  11. Write the C++ code to (1) free the memory associated with the array flags and (2) "NULL out" flags.
    Answer:

Total points for this book learning challenge:

150 points