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

...

7 Коммитов

Автор SHA1 Сообщение Дата
GladkyMS 7d912af179 personal variant
1 год назад
GladkyMS f32bc01b85 5:svg format
1 год назад
GladkyMS 903f95582d 4:unit tests
1 год назад
GladkyMS b8b299940f 3:modules files
1 год назад
GladkyMS d1704056b8 3:created modules
1 год назад
GladkyMS 9168108fc3 2:structuring with functions
1 год назад
GladkyMS a9261560c8 access keys
1 год назад

Разница между файлами не показана из-за своего большого размера Загрузить разницу

@ -0,0 +1,38 @@
#include "histogram.h"
void find_minmax(const std::vector<double>& numbers, double& min, double& max) {
min = numbers[0];
max = numbers[0];
for (double x : numbers)
{
if (x < min)
min = x;
else if (x > max)
max = x;
}
}
std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bin_count) {
double min, max;
find_minmax(numbers, min, max);
std::vector<size_t> bins(bin_count);
double bin_size = (max - min) / bin_count;
for (size_t i = 0; i < numbers.size(); i++)
{
bool found = false;
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
{
auto low = min + j * bin_size;
auto high = min + (j + 1) * bin_size;
if ((low <= numbers[i]) && (numbers[i] < high))
{
bins[j]++;
found = true;
}
}
if (!found)
{
bins[bin_count - 1]++;
}
}
return bins;
}

@ -0,0 +1,5 @@
#pragma once
#include <vector>
std::vector<size_t>
make_histogram(const std::vector<double>& numbers, size_t bin_count);

@ -0,0 +1,4 @@
#pragma once
#include <vector>
void find_minmax(const std::vector<double>& numbers, double& min, double& max);

@ -0,0 +1,59 @@
#include "svg.h"
#include <iostream>
#include<string>
void svg_begin(double width, double height) {
std::cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
std::cout << "<svg ";
std::cout << "width='" << width << "' ";
std::cout << "height='" << height << "' ";
std::cout << "viewBox='0 0 " << width << " " << height << "' ";
std::cout << "xmlns='http://www.w3.org/2000/svg'>\n";
}
void svg_end() {
std::cout << "</svg>\n";
}
void
svg_text(double left, double baseline, std::string text) {
std::cout << "<text x='" << left << "' y='" << baseline << "'>"<<text<<"</text>";
}
void svg_rect(double x, double y, double width, double height,std::string stroke = "black", std::string fill = "black") {
std::cout << "<rect x='"<<x<<"' y='"<<y<<"' width='"<<width<<"' height='"<<height<<"' stroke='"<<stroke<<"' fill='"<<fill<<"'/>";
}
void show_histogram_svg(const std::vector<size_t>& bins, size_t bin_count) {
const auto IMAGE_WIDTH = 400;
const auto IMAGE_HEIGHT = 300;
const auto TEXT_LEFT = 20;
const auto TEXT_BASELINE = 20;
const auto TEXT_WIDTH = 50;
const auto BIN_HEIGHT = 30;
const auto BLOCK_WIDTH = 10;
double mxbins = bins[0];
for (double x : bins)
{
if (x > mxbins)
mxbins = x;
}
double k;
if (mxbins > IMAGE_WIDTH-TEXT_WIDTH)
k = floor((IMAGE_WIDTH - TEXT_WIDTH) / mxbins);
else
k = 1;
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
double top = 0;
for (size_t bin : bins) {
int key = (10 - floor((bin) * 9 / mxbins));
std::string color = "#" +std::to_string(key)+ std::to_string(key)+ std::to_string(key);
const double bin_width = BLOCK_WIDTH * bin*k;
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT,color,color);
top += BIN_HEIGHT;
}
svg_end();
}

@ -0,0 +1,4 @@
#pragma once
#include <vector>
void show_histogram_svg(const std::vector<size_t>& bins, size_t bin_count);

@ -0,0 +1,33 @@
#include "text.h"
#include <iostream>
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
void show_histogram_text(std::vector<size_t> bins, size_t bin_count) {
double mxbins = bins[0];
for (double x : bins)
{
if (x > mxbins)
mxbins = x;
}
double k;
if (mxbins > MAX_ASTERISK)
k = MAX_ASTERISK / mxbins;
else
k = 1;
for (size_t i = 0; i < bin_count; i++)
{
if (bins[i] < 10) {
std::cout << " ";
}
else if (bins[i] < 100) {
std::cout << " ";
}
std::cout << bins[i] << "|";
for (int j = 0; j < floor(bins[i] * k); j++)
{
std::cout << "*";
}
std::cout << std::endl;
}
}

@ -0,0 +1,4 @@
#pragma once
#include <vector>
void show_histogram_text(std::vector<size_t> bins, size_t bin_count);

@ -1,81 +1,39 @@
#include <vector>
#include <iostream>
#include<cmath>
#include "histogram.h"
#include "text.h"
#include "svg.h"
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
using namespace std;
int main()
struct Input {
vector<double> numbers;
size_t bin_count{};
};
Input input_data()
{
size_t number_count;
cerr << "Enter number count: ";
cin >> number_count;
vector<double> numbers(number_count);
for (int i = 0; i < number_count; i++)
{
cin >> numbers[i];
}
double min = numbers[0];
double max = numbers[0];
for (double x : numbers)
{
if (x < min)
min = x;
else if (x > max)
max = x;
}
size_t bin_count=3;
vector<size_t> bins(bin_count);
double bin_size = (max - min) / bin_count;
Input in;
in.numbers.resize(number_count);
for (size_t i = 0; i < number_count; i++)
{
bool found = false;
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
{
auto low = min + j * bin_size;
auto high = min + (j + 1) * bin_size;
if ((low <= numbers[i]) && (numbers[i] < high))
{
bins[j]++;
found = true;
}
}
if (!found)
{
bins[bin_count - 1]++;
}
}
double mxbins = bins[0];
cin >> in.numbers[i];
for (double x : bins)
{
if (x > mxbins)
mxbins = x;
}
double k;
if (mxbins > MAX_ASTERISK)
k = MAX_ASTERISK / mxbins;
else
k = 1;
for (size_t i = 0; i < bin_count; i++)
{
if (bins[i] < 10) {
cout << " ";
}
else if (bins[i] < 100) {
cout << " ";
}
cout << bins[i] << "|";
cin >> in.bin_count;
return in;
}
for (int j = 0; j < floor(bins[i] * k); j++)
{
cout << "*";
}
cout << endl;
}
int main()
{
Input in = input_data();
vector <size_t> bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins, in.bin_count);
}

@ -127,8 +127,17 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="histogram.cpp" />
<ClCompile Include="svg.cpp" />
<ClCompile Include="text.cpp" />
<ClCompile Include="vector.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="histogram.h" />
<ClInclude Include="histogram_internal.h" />
<ClInclude Include="svg.h" />
<ClInclude Include="text.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

@ -18,5 +18,28 @@
<ClCompile Include="vector.cpp">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="histogram.cpp">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="text.cpp">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="svg.cpp">
<Filter>Исходные файлы</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="histogram.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
<ClInclude Include="text.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
<ClInclude Include="histogram_internal.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
<ClInclude Include="svg.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
</ItemGroup>
</Project>

@ -0,0 +1,7 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACAMdZJ6jcrCTG4zN60ikNurnykEEOGpX9wjEHifeyX64wAAAJCTOx1fkzsd
XwAAAAtzc2gtZWQyNTUxOQAAACAMdZJ6jcrCTG4zN60ikNurnykEEOGpX9wjEHifeyX64w
AAAECDxICPuo/qkgxFfhB8sMFCW719N0gZe8TuxBWg+RlbhAx1knqNysJMbjM3rSKQ26uf
KQQQ4alf3CMQeJ97JfrjAAAAC2dsYWRtQE1heGdsAQI=
-----END OPENSSH PRIVATE KEY-----

@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAx1knqNysJMbjM3rSKQ26ufKQQQ4alf3CMQeJ97Jfrj gladm@Maxgl
Загрузка…
Отмена
Сохранить