diff --git a/main.cpp b/main.cpp index 5e6d04f..59c6f19 100644 --- a/main.cpp +++ b/main.cpp @@ -24,7 +24,9 @@ double promptd(string,bool*); string prompts(string,bool*); double avg(std::list*); void countw(std::list&, wordcount*); -void histogram(int); +void histogram(wordcount&); +void spacep(int); +void histogramp(int); int main() { printlm("Get histogram of input:"); @@ -37,11 +39,7 @@ int main() { printlm("Histogram:"); wordcount wc {}; countw(lst,&wc); - for (const auto c : wc) { - printm(c.first); - printm(" "); - histogram(c.second); - } + histogram(wc); return 0; } @@ -96,6 +94,20 @@ void countw(std::list &values, wordcount *holder) { } } -void histogram(int num) { +void histogram(wordcount &wc) { + int maxl {}; + for (const auto c : wc) if (c.first.length() > maxl) maxl = c.first.length(); + for (const auto c : wc) { + printm(c.first); + spacep(1 + maxl - c.first.length()); + histogramp(c.second); + } +} + +void spacep(int num) { + for (auto i = 0; i < num; ++i) printm(" "); +} + +void histogramp(int num) { for (auto i = 1; i <= num; ++i) if (i == num) printlm("*"); else printm("*"); } diff --git a/main.o b/main.o index 33a05da..11252bf 100644 Binary files a/main.o and b/main.o differ diff --git a/t b/t index 9f66dcd..c3d7219 100755 Binary files a/t and b/t differ