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

Function show_words

Examples/NoModules/Chapter 08/Ex8_17.cpp:95–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93}
94
95void show_words(const Words& words)
96{
97 const size_t field_width {max_word_length(words) + 1};
98 const size_t words_per_line {8};
99 std::cout << std::format("{:{}}", *words[0], field_width); // Output first word
100
101 size_t words_in_line {}; // Number of words in current line
102 for (size_t i {1}; i < words.size(); ++i)
103 { // Output newline when initial letter changes or after 8 per line
104 if ((*words[i])[0] != (*words[i - 1])[0] || ++words_in_line == words_per_line)
105 {
106 words_in_line = 0;
107 std::cout << std::endl;
108 }
109 std::cout << std::format("{:{}}", *words[i], field_width); // Output a word
110 }
111 std::cout << std::endl;
112}

Callers 1

mainFunction · 0.70

Calls 2

max_word_lengthFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected