code: Первые изменения с лабой 4
Этот коммит содержится в:
@@ -1,9 +1,12 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<svg width='400' height='300' viewBox='0 0 400 300' xmlns='http://www.w3.org/2000/svg'>
|
||||
<svg width='600' height='400' viewBox='0 0 600 400' xmlns='http://www.w3.org/2000/svg'>
|
||||
<text x='20' y='20'>2</text>
|
||||
<rect x='50' y='0' width='140' height='30' stroke='grey' fill='#e3c3c7' />
|
||||
<rect x='50' y='0' width='140' height='30' stroke='grey' fill='#6c6835' />
|
||||
<text x='450' y='20'>20%</text>
|
||||
<text x='20' y='50'>5</text>
|
||||
<rect x='50' y='30' width='350' height='30' stroke='grey' fill='#9efffa' />
|
||||
<rect x='50' y='30' width='350' height='30' stroke='grey' fill='#dee670' />
|
||||
<text x='450' y='50'>50%</text>
|
||||
<text x='20' y='80'>3</text>
|
||||
<rect x='50' y='60' width='210' height='30' stroke='grey' fill='#6f092f' />
|
||||
<rect x='50' y='60' width='210' height='30' stroke='grey' fill='#6aa11b' />
|
||||
<text x='450' y='80'>30%</text>
|
||||
</svg>
|
||||
|
||||
|
До Ширина: | Высота: | Размер: 448 B После Ширина: | Высота: | Размер: 544 B |
@@ -17,7 +17,7 @@ struct Input {
|
||||
|
||||
Input
|
||||
|
||||
input_data() {
|
||||
input_data(istream& hin) {
|
||||
// Функция ввода
|
||||
//Создание переменных
|
||||
|
||||
@@ -27,19 +27,19 @@ input_data() {
|
||||
// Ввод переменных
|
||||
|
||||
cerr << "Enter number count: " << endl;
|
||||
cin >> number_count;
|
||||
hin >> number_count;
|
||||
|
||||
in.numbers.resize(number_count);
|
||||
|
||||
cerr << "Enter numbers: " << endl;
|
||||
|
||||
for (int i = 0; i < number_count; i++) {
|
||||
cin >> in.numbers[i];
|
||||
hin >> in.numbers[i];
|
||||
|
||||
}
|
||||
|
||||
cerr << "Enter bin count: " << endl;
|
||||
cin >> in.bin_count;
|
||||
hin >> in.bin_count;
|
||||
|
||||
return in;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ input_data() {
|
||||
int main()
|
||||
{
|
||||
// Функция main
|
||||
auto in = input_data(); // Ввод структуры
|
||||
auto in = input_data(cin); // Ввод структуры
|
||||
auto bins = make_histogram(in.numbers, in.bin_count); // Распределние по корзинам
|
||||
show_histogram_svg(bins); // Вывод графика
|
||||
|
||||
|
||||
@@ -4,10 +4,15 @@
|
||||
#include "histogram_internal.h"
|
||||
using namespace std;
|
||||
|
||||
bool find_minmax(const vector<double>& numbers, double& min_in_numbers, double& max_in_numbers) {
|
||||
|
||||
if (numbers.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void find_minmax(const vector<double>& numbers, double& min_in_numbers, double& max_in_numbers) {
|
||||
min_in_numbers = numbers[0];
|
||||
max_in_numbers = *(max_element(begin(numbers), end(numbers)));
|
||||
min_in_numbers = *(min_element(begin(numbers), end(numbers)));
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
void find_minmax(const std::vector<double>& numbers, double& min_in_numbers, double& max_in_numbers);
|
||||
bool find_minmax(const std::vector<double>& numbers, double& min_in_numbers, double& max_in_numbers);
|
||||
|
||||
#endif //INTERNAL_H_INCLUDED
|
||||
|
||||
@@ -65,22 +65,30 @@ show_histogram_svg(const vector<size_t> bins) {
|
||||
const auto TEXT_BASELINE = 20;
|
||||
const auto TEXT_WIDTH = 50;
|
||||
const auto BIN_HEIGHT = 30;
|
||||
const auto PROCENT_SPACE = 50;
|
||||
auto BLOCK_WIDTH = 10;
|
||||
auto sum_bins = 0;
|
||||
|
||||
BLOCK_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH) / mm;
|
||||
|
||||
svg_begin(400, 300);
|
||||
svg_begin(600, 400);
|
||||
|
||||
|
||||
for (size_t Elem : bins) {
|
||||
sum_bins += Elem;
|
||||
}
|
||||
|
||||
double top = 0;
|
||||
for (size_t bin : bins) {
|
||||
const double bin_width = BLOCK_WIDTH * bin;
|
||||
|
||||
double PROCENT = double(bin) / double(sum_bins);
|
||||
PROCENT = round(PROCENT * 100) / 100 ;
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "grey", getRandomHexColor());
|
||||
|
||||
svg_text(IMAGE_WIDTH + PROCENT_SPACE, top + TEXT_BASELINE, to_string(int(PROCENT * 100)) + "%");
|
||||
top += BIN_HEIGHT;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -15,28 +15,28 @@ TEST_CASE("distinct positive numbers") {
|
||||
TEST_CASE("empty vector") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({}, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 2);
|
||||
CHECK(!find_minmax({}, min, max));
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("you fill so lonly") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({ 1 }, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 2);
|
||||
CHECK(max == 1);
|
||||
}
|
||||
TEST_CASE("negative numbers") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({ -1, -2 }, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 2);
|
||||
CHECK(min == -2);
|
||||
CHECK(max == -1);
|
||||
}
|
||||
TEST_CASE("twins") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({ 1, 1 }, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 2);
|
||||
CHECK(max == 1);
|
||||
}
|
||||
Ссылка в новой задаче
Block a user