#include #include "string.h" #include "vector.h" #pragma once class istream; istream & operator >> (istream & in, string & str) // see text p 108 { char inbuffer[1000]; in >> inbuffer; str = inbuffer; return in; } void main () { // program to tally occurrences of words by length in the standard input // group all words larger than 20 characters into bigwords category // see text pp. 148-149 vector counts(20, 0); int bigwords = 0 ; string word; cout << "Enter any input text, terminated by ctrl-d\n"; while (cin >> word) { int wordlen = word.length(); if (wordlen <= 20) counts[wordlen-1] ++ ; else bigwords ++; } cout << "The word lengths and their frequencies are:" << "\n\n" ; for (int i=1; i<=20; i++) if (counts[i-1] > 0) cout << i << '\t' << counts[i-1] << '\n' ; if (bigwords > 0) cout << ">20 \t" << bigwords << '\n' ; }