MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / show_words

Method show_words

Exercises/Modules/Chapter 11/Soln11_06/words.cpp:70–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70void words::show_words(const Words& words)
71{
72 const size_t field_width {max_word_length(words) + 1};
73 const size_t words_per_line {8};
74 std::cout << std::format("{:{}}", *words[0], field_width); // Output first word
75
76 size_t words_in_line {}; // Number of words in current line
77 for (size_t i {1}; i < words.size(); ++i)
78 { // Output newline when initial letter changes or after 8 per line
79 if ((*words[i])[0] != (*words[i - 1])[0] || ++words_in_line == words_per_line)
80 {
81 words_in_line = 0;
82 std::cout << std::endl;
83 }
84 std::cout << std::format("{:{}}", *words[i], field_width); // Output a word
85 }
86 std::cout << std::endl;
87}

Callers

nothing calls this directly

Calls 2

max_word_lengthFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected