Сравнить коммиты

...

4 Коммитов

@ -1,3 +1,4 @@
#include <curl/curl.h>
#include <vector>
#include <iostream>
#include <string>
@ -11,31 +12,36 @@ struct Input {
};
Input
input_data() {
input_data(istream& in, bool prompt) {
size_t number_count;
cerr << "Enter number count: ";
cin >> number_count;
if (prompt) {cerr << "Enter number count: ";};
in >> number_count;
Input in;
in.numbers.resize(number_count);
cerr << "Enter numbers: ";
Input in1;
in1.numbers.resize(number_count);
if (prompt) {cerr << "Enter numbers: ";};
for (size_t i = 0; i < number_count; i++) {
cin >> in.numbers[i];
in >> in1.numbers[i];
}
cerr << "Enter bin count: ";
cin >> in.bin_count;
if (prompt) {cerr << "Enter bin count: ";};
in >> in1.bin_count;
return in;
return in1;
;
}
int main()
{
#include <curl/curl.h>
curl_global_init(CURL_GLOBAL_ALL);
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
bool prompt = true;
auto in = input_data();
auto in = input_data(cin, prompt);
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins);
return 0;

@ -41,12 +41,19 @@ show_histogram_svg(const vector<double>& bins) {
const auto BLOCK_WIDTH = 10;
double average = 0, sum =0, scale=1;
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) {
max_count = (bin * BLOCK_WIDTH);
}
}
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;
@ -56,7 +63,12 @@ show_histogram_svg(const vector<double>& bins) {
average = sum / bins.size();
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));
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");
}
if (bin > average) {
svg_rect(TEXT_WIDTH, top, bin_width / scale, BIN_HEIGHT, "yellow", "red");
}

Загрузка…
Отмена
Сохранить