Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

zipfreq.cpp: The zipfreq program: 1. reads a token stream from standard input, 2

ID: 3564101 • Letter: Z

Question

zipfreq.cpp: The zipfreq program:

1. reads a token stream from standard input,

2. picking out zipcodes which are assumed to be 5 character strings preceded by the token "zip:".

3. The program prints the top 10 most frequently occuring zipcodes and their frequency, in descending order of frequency.

4. Each line should have the form: zipcode frequency.

5. In the case where two lines have the same frequency, the zipcode with the lower number should come first (so 11210 comes before 11217).

6. If there are FEWER than 10 entries, then they all should be printed, in the sorted fashion described above.

Explanation / Answer

#include #include #include using namespace std; int main() { int i=0, n=0, l=0, c=0, temp2, flag=1; string zipsstring, zipsstringf, temp1; string stringarray[10000]; int countarray[10000]={0}; cin >> zipsstring; while(cin.get() && !cin.fail()) { if(zipsstring.find("zip:", n != std::string::npos)) { zipsstringf=zipsstring.substr(4, 5); for(int i=0; i> zipsstring; } for(int i=0; i