Answers to Self-Review Exercises

  1. 7.1

    1. arrays, vectors.

    2. array name, type.

    3. subscript or index.

    4. constant variable.

    5. sorting.

    6. searching.

    7. two-dimensional.

  2. 7.2

    1. False. An array can store only values of the same type.

    2. False. An array subscript should be an integer or an integer expression.

    3. False. The remaining elements are initialized to zero.

    4. True.

  3. 7.3

    1. const size_t arraySize{10};

    2. array<double, arraySize> fractions{0.0};

    3. fractions[3]

    4. fractions[4]

    5. fractions[9] = 1.667;

    6. fractions[6] = 3.333;

    7.  

      
      cout << fixed << setprecision(2);
      cout << fractions[6] << ' ' << fractions[9] << endl;
      Output: 3.33 1.67
      
    8.  

      
      for (size_t i{0}; i < fractions.size(); ++i) {
         cout << "fractions[" << i << "] = " << fractions[i] << endl;
      }
      Output: fractions[0] = 0.0 fractions[1] ...

Get C++ How to Program, 10/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.