// word\_len\_histo.cpp : reads words and lists distribution // of word lengths. // Fred Swartz, 2002-09-01 // This would be nice to turn into an OO program, where // a class represented a distribution of values. // Some elements which are globals here would turn into // private member elements in the class (eg, valueCount). //--- includes #include <iostream> #include <iomanip> #include <cctype> using namespace std; //--- prototypes void countValue(int cnt); float getAverage(); //--- constants const int BINS = 21; // how many numbers can be counted //--- globals int valueCount
BINS; // bins used for counting each number int totalChars = 0; // total number of characters //=========================================================== main int main() { char c; // input character int wordLen = 0; // 0 if not in word, else word length //--- Initialize counts to zero for (int i=0; i valueCount
i = 0; } //--- Read chars in loop and decide if in a word or not.
[Read More]