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

Function show_data

Exercises/NoModules/Chapter 09/Soln9_03.cpp:32–46  ·  view source on GitHub ↗

Outputs an array of double values

Source from the content-addressed store, hash-verified

30
31// Outputs an array of double values
32void show_data(std::span<const double> data,
33 std::string_view title, size_t width, size_t perLine)
34{
35 std::cout << title << std::endl; // Display the title
36
37 // Output the data values
38 for (size_t i {}; i < data.size(); ++i)
39 {
40 // Display a data item (uses a dynamic field width: see Chapter 7)
41 std::cout << std::format("{:{}.6g}", data[i], width);
42 if ((i + 1) % perLine == 0) // Newline after perLine values
43 std::cout << '\n';
44 }
45 std::cout << std::endl;
46}
47
48std::optional<double> smallest(std::span<const double> data)
49{

Callers 1

mainFunction · 0.70

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected