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

Function show_words

Examples/Modules/Chapter 08/Ex8_17.cpp:96–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 7

mainFunction · 0.70
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50

Calls 2

max_word_lengthFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected