|
|
|
@ -2,22 +2,22 @@
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include "histogram.h"
|
|
|
|
|
#include "text.h"
|
|
|
|
|
#include "svg.h"
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
struct Input {
|
|
|
|
|
vector<double> numbers;
|
|
|
|
|
size_t bin_count{};
|
|
|
|
|
size_t bin_count;
|
|
|
|
|
size_t image_width;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Ââîä äàííûõ
|
|
|
|
|
Input input_data() {
|
|
|
|
|
Input in;
|
|
|
|
|
size_t number_count;
|
|
|
|
|
cerr << "Enter number count: ";
|
|
|
|
|
cin >> number_count;
|
|
|
|
|
|
|
|
|
|
Input in;
|
|
|
|
|
in.numbers.resize(number_count);
|
|
|
|
|
|
|
|
|
|
cerr << "Enter numbers: ";
|
|
|
|
|
for (size_t i = 0; i < number_count; i++) {
|
|
|
|
|
cin >> in.numbers[i];
|
|
|
|
@ -26,18 +26,32 @@ Input input_data() {
|
|
|
|
|
cerr << "Enter bin count: ";
|
|
|
|
|
cin >> in.bin_count;
|
|
|
|
|
|
|
|
|
|
return in;
|
|
|
|
|
const size_t BLOCK_WIDTH = 10;
|
|
|
|
|
const size_t MIN_WIDTH = 70;
|
|
|
|
|
const size_t MAX_WIDTH = 800;
|
|
|
|
|
size_t required_min_width = number_count * BLOCK_WIDTH / 3;
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
cerr << "Enter image width (" << MIN_WIDTH << "-" << MAX_WIDTH << "), minimum " << required_min_width << ": ";
|
|
|
|
|
cin >> in.image_width;
|
|
|
|
|
|
|
|
|
|
if (in.image_width < MIN_WIDTH) {
|
|
|
|
|
cerr << "Width is too small (minimum " << MIN_WIDTH << ")\n";
|
|
|
|
|
} else if (in.image_width > MAX_WIDTH) {
|
|
|
|
|
cerr << "Width is too large (maximum " << MAX_WIDTH << ")\n";
|
|
|
|
|
} else if (in.image_width < required_min_width) {
|
|
|
|
|
cerr << "Width is less than 1/3 of numbers count * block width (" << required_min_width << ")\n";
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Âûâîä ãèñòîãðàììû
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Îñíîâíàÿ ôóíêöèÿ
|
|
|
|
|
int main() {
|
|
|
|
|
Input in = input_data();
|
|
|
|
|
vector<size_t> bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
|
show_histogram_text(bins);
|
|
|
|
|
auto in = input_data();
|
|
|
|
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
|
show_histogram_svg(bins, in.image_width);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|