Not logged in. Log in with GitHub. About Websheets.

List of all available Websheets


Viewing cpp/cs104/stl/zip_map by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
PropertyValue
Description
html markup
shown to student
 
Read zip code integers from <tt>cin</tt>.  Then create a map of each zip code and its number of occurrences.  Then print out that data.
Engine
Template / Reference solution
 
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(int argc, char *argv[])
{
  vector<int> all_zips;
  int zipCode;
  while(cin >> zipCode){
    all_zips.push_back(zipCode);
  }
  // Create a map of zipcode and the count of its occurrences
\[
REDACTED
]\
  // Note: In the above we could have created the map entries as we 
  //       read in the zips from 'cin' but we wanted you to practice
  //       iterating over a vector.
   
  cout << "Zip code, occurrence table" << endl;
   
  // Now write the for loop to iterate over the map entries 
\[
REDACTED
]\  
  {
    cout << \[ REDACTED ]\ << " occurs " << \[ REDACTED ]\ << " times" << endl;
  }
  return 0;
}
C++ test suite
json list of stdin/args tests
e.g. [{"stdin":"hi", "args":["4", "5"]},
{"stdin":"noargs"}]

to just run once with no input use [{}]
 
[{"stdin":"90018 90018 90007 90018 90089 90007 90006"}]


Optional properties:

Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.