histogram prettified
This commit is contained in:
parent
5f5d16d890
commit
4228d34719
26
main.cpp
26
main.cpp
@ -24,7 +24,9 @@ double promptd(string,bool*);
|
||||
string prompts(string,bool*);
|
||||
double avg(std::list<double>*);
|
||||
void countw(std::list<string>&, 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<string> &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("*");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user