csci 20 :: book learning challenge 13 (due tues, apr 26)
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: The STL Vector Class, Beginner's Guide to std::vector, std::vector, and std::vector, then answer the following:

Your name:
  1. What is a vector in C++?
    Answer:
  2. Write the C++ include statement required for using a vector in a program.
    Answer:
  3. Write the C++ code to do the following:
    • declare a vector of strings called cities
    • declare a vector of integers called populations

    Answer:
  4. Write the C++ code to add the following data pairs to the cities and populations vectors:
    • "Los Angeles", 3928864
    • "San Diego", 1381069
    • "San Jose", 1015785
    • "San Francisco", 852469
    • "Fresno", 515986

    Answer:
  5. Write the C++ code to display the number of items in the cities vector, formatted as follows (replace NUMBER with the size of the cities vector):

    Number of cities: NUMBER
    Answer:
  6. Write the C++ code to display the cities stored in the cities vector, using the at() vector function, one city per line.
    Answer:
  7. Write the C++ code to display the city/population pairs from the cities and populations vectors, using operator [], formatted as follows (replace CITY with cities entries and POPULATION with the associated entries from populations):

    CITY, pop. POPULATION
    Answer:
  8. Write the C++ code to add the following data pairs to the cities and populations vectors:
    • "Sacramento", 485199
    • "Long Beach", 473577
    • "Oakland", 413775
    • "Bakersfield", 368759
    • "Anaheim", 346997

    Answer:
  9. Write the C++ code to sum the populations of the ten (10) data pairs that should now be in the cities/populations vectors. Use the int variable totalPopulation declared below, following the format below (replace POPULATION with the computed total):

    int totalPopulation = 0;

    Total population in top ten CA cities: POPULATION
    Answer:
  10. Write the C++ code to compute and display the average population (rounded to int value) of the ten (10) cities represented as data pairs that should be in the cities/populations vectors. Use the totalPopulation value computed in the question above. Use the size of the populations vector (NOT a hard-coded 10) as the divisor/denominator in your calculation. Format as follows (replace AVERAGE with the result of the computation):

    Average population in top ten CA cities: AVERAGE
    Answer:

Total points for this book learning challenge:

150 points