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:

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

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

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
6. Write the C++ code to display the cities stored in the cities vector, using the at() vector function, one city per line.
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
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

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