diff --git a/1st try.cbp b/1st try.cbp index fb679d6..d441e6f 100644 --- a/1st try.cbp +++ b/1st try.cbp @@ -32,7 +32,13 @@ + + + + + + diff --git a/main.cpp b/main.cpp index 08c7870..828c751 100644 --- a/main.cpp +++ b/main.cpp @@ -23,6 +23,7 @@ input_data(istream& in) { in >> in1.numbers[i]; } + cerr << "Enter bin count: "; in >> in1.bin_count; @@ -33,6 +34,7 @@ int main() { const size_t SCREEN_WIDTH = 80; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + bool prompt = true; auto in = input_data(cin); auto bins = make_histogram(in.numbers, in.bin_count); diff --git a/svg.cpp b/svg.cpp index 2e82799..b6122c9 100644 --- a/svg.cpp +++ b/svg.cpp @@ -41,6 +41,7 @@ show_histogram_svg(const vector& bins) { const auto BLOCK_WIDTH = 10; const auto MAX_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH); + double sum = 0; double max_count = (bins[0] * BLOCK_WIDTH); for (double bin: bins){ if ((bin * BLOCK_WIDTH) > max_count) { @@ -48,12 +49,24 @@ show_histogram_svg(const vector& bins) { } } + for (double bin: bins){ + sum = sum + (MAX_WIDTH * ((BLOCK_WIDTH * bin) / max_count)); + } + + double avg_width = sum/bins.size(); + + svg_begin(400, 300); double top = 0; for (double bin : bins) { const double bin_width = MAX_WIDTH * ((BLOCK_WIDTH * bin) / max_count); svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "#aaffaa"); + if (bin_width > avg_width){ + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", "#e71320"); + } + else { + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", "#2fe713"); + } top += BIN_HEIGHT; } svg_end(); diff --git a/unittest.cbp b/unittest.cbp index 7f9621b..adcfbf4 100644 --- a/unittest.cbp +++ b/unittest.cbp @@ -31,6 +31,8 @@ + +