Сравнить коммиты
14 Коммитов
cf465317f2
...
538508ef98
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
538508ef98 | ||
|
|
ec765e16b4 | ||
|
|
54fc874282 | ||
|
|
37124aec8f | ||
|
|
85ba83fd45 | ||
|
|
a5c6f91238 | ||
|
|
1c78ed9cd8 | ||
|
|
b8b8b22817 | ||
|
|
4ee24ceecb | ||
|
|
b0563042c3 | ||
|
|
08470acf11 | ||
|
|
29f51bb555 | ||
|
|
934f4788fb | ||
|
|
d056da7c77 |
5
.gitignore
поставляемый
5
.gitignore
поставляемый
@@ -1,4 +1,9 @@
|
||||
ProgUit Lab1.vcxproj
|
||||
ProgUit Lab1.vcxproj.filters
|
||||
ProgUit Lab1.vcxproj.user
|
||||
ProgUit Lab1/ARM64
|
||||
/ARM64
|
||||
/unittest.vcxproj
|
||||
/unittest.vcxproj.filters
|
||||
/unittest.vcxproj.user
|
||||
|
||||
|
||||
9
ARM64/Debug/marks.svg
Обычный файл
9
ARM64/Debug/marks.svg
Обычный файл
@@ -0,0 +1,9 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<svg width='400' height='300' viewBox='0 0 400 300' 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='#319c28' />
|
||||
<text x='20' y='50'>5</text>
|
||||
<rect x='50' y='30' width='350' height='30' stroke='grey' fill='#7d79c6' />
|
||||
<text x='20' y='80'>3</text>
|
||||
<rect x='50' y='60' width='210' height='30' stroke='grey' fill='#5e7341' />
|
||||
</svg>
|
||||
|
После Ширина: | Высота: | Размер: 448 B |
3
ARM64/Debug/marks.txt
Обычный файл
3
ARM64/Debug/marks.txt
Обычный файл
@@ -0,0 +1,3 @@
|
||||
10
|
||||
3 3 4 4 4 4 4 5 5 5
|
||||
3
|
||||
@@ -1,111 +1,67 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "histogram.h"
|
||||
#include "text.h"
|
||||
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
// Объявление переменных
|
||||
size_t number_count;
|
||||
struct Input {
|
||||
// Создание структуры
|
||||
vector <double> numbers;
|
||||
size_t bin_count;
|
||||
size_t bin_count{};
|
||||
};
|
||||
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
Input
|
||||
|
||||
size_t User_Diagram;
|
||||
input_data() {
|
||||
// Функция ввода
|
||||
//Создание переменных
|
||||
|
||||
size_t number_count;
|
||||
Input in;
|
||||
|
||||
// Ввод переменных
|
||||
|
||||
cerr << "Enter number count: " << endl;
|
||||
cin >> number_count;
|
||||
|
||||
numbers.resize(number_count);
|
||||
in.numbers.resize(number_count);
|
||||
|
||||
cerr << "Enter numbers: " << endl;
|
||||
|
||||
for (int i = 0; i < number_count; i++) {
|
||||
cin >> numbers[i];
|
||||
cin >> in.numbers[i];
|
||||
|
||||
}
|
||||
|
||||
cerr << "Enter bin count: " << endl;
|
||||
cin >> bin_count;
|
||||
cin >> in.bin_count;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
// Объявление перменных промежуточных/вывода
|
||||
|
||||
vector <size_t> bins(bin_count);
|
||||
double max_in_numbers = *(max_element(begin(numbers), end(numbers)));
|
||||
double min_in_numbers = *(min_element(begin(numbers), end(numbers)));
|
||||
|
||||
|
||||
double bin_size = (max_in_numbers - min_in_numbers) / bin_count;
|
||||
|
||||
int max_in_bins = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
// Функция main
|
||||
auto in = input_data(); // Ввод структуры
|
||||
auto bins = make_histogram(in.numbers, in.bin_count); // Распределние по корзинам
|
||||
show_histogram_svg(bins); // Вывод графика
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Код
|
||||
|
||||
for (size_t i = 0; i < number_count; i++) {
|
||||
int to_bin = int((numbers[i]) - min_in_numbers) / bin_size;
|
||||
if (to_bin >= bin_count) {
|
||||
bins[to_bin - 1]++;
|
||||
}
|
||||
else {
|
||||
bins[to_bin]++;
|
||||
}
|
||||
}
|
||||
// Максимальное в коорзинах
|
||||
for (int i = 0; i < bin_count; i++) {
|
||||
if (bins[i] > max_in_bins) {
|
||||
max_in_bins = bins[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (max_in_bins > MAX_ASTERISK) {
|
||||
|
||||
for (int i = 0; i < bin_count; i++) {
|
||||
if (bins[i] < 100) {
|
||||
cout << " ";
|
||||
}
|
||||
if (bins[i] < 10) {
|
||||
cout << " ";
|
||||
}
|
||||
size_t height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_in_bins);
|
||||
|
||||
cout << bins[i] << "|";
|
||||
|
||||
|
||||
for (int j = 0; j < height; j++) {
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
// Если максимальное число среди коорзин меньше или равно 76
|
||||
for (int i = 0; i < bin_count; i++) {
|
||||
if (bins[i] < 100) {
|
||||
cout << " ";
|
||||
}
|
||||
if (bins[i] < 10) {
|
||||
cout << " ";
|
||||
}
|
||||
|
||||
|
||||
cout << bins[i] << "|";
|
||||
for (int j = 0; j < bins[i]; j++) {
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
7106
ProgUit Lab1/doctest.h
Обычный файл
7106
ProgUit Lab1/doctest.h
Обычный файл
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
32
ProgUit Lab1/histogram.cpp
Обычный файл
32
ProgUit Lab1/histogram.cpp
Обычный файл
@@ -0,0 +1,32 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "histogram.h"
|
||||
#include "histogram_internal.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
|
||||
vector <size_t> make_histogram(const vector<double>& numbers, const size_t bin_count) {
|
||||
|
||||
vector <size_t> bins(bin_count);
|
||||
|
||||
double min_in_numbers, max_in_numbers;
|
||||
find_minmax(numbers, min_in_numbers, max_in_numbers);
|
||||
double bin_size = (max_in_numbers - min_in_numbers) / bin_count;
|
||||
|
||||
for (size_t i = 0; i < numbers.size(); i++) {
|
||||
int to_bin = int((numbers[i]) - min_in_numbers) / bin_size;
|
||||
if (to_bin >= bin_count) {
|
||||
bins[to_bin - 1]++;
|
||||
}
|
||||
else {
|
||||
bins[to_bin]++;
|
||||
}
|
||||
}
|
||||
|
||||
return bins;
|
||||
}
|
||||
12
ProgUit Lab1/histogram.h
Обычный файл
12
ProgUit Lab1/histogram.h
Обычный файл
@@ -0,0 +1,12 @@
|
||||
#ifndef HISTOGRAM_H_INCLUDED
|
||||
#define HISTOGRAM_H_INCLUDED
|
||||
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
||||
std::vector<size_t>
|
||||
make_histogram(const std::vector<double>& numbers, size_t bin_count);
|
||||
|
||||
|
||||
#endif // HISTOGRAM_H_INCLUDED
|
||||
13
ProgUit Lab1/histogram_internal.cpp
Обычный файл
13
ProgUit Lab1/histogram_internal.cpp
Обычный файл
@@ -0,0 +1,13 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "histogram_internal.h"
|
||||
using namespace std;
|
||||
|
||||
|
||||
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)));
|
||||
|
||||
}
|
||||
8
ProgUit Lab1/histogram_internal.h
Обычный файл
8
ProgUit Lab1/histogram_internal.h
Обычный файл
@@ -0,0 +1,8 @@
|
||||
#ifndef INTERNAL_H_INCLUDED
|
||||
#define INTERNAL_H_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
|
||||
void find_minmax(const std::vector<double>& numbers, double& min_in_numbers, double& max_in_numbers);
|
||||
|
||||
#endif //INTERNAL_H_INCLUDED
|
||||
96
ProgUit Lab1/text.cpp
Обычный файл
96
ProgUit Lab1/text.cpp
Обычный файл
@@ -0,0 +1,96 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#include "text.h"
|
||||
#include "histogram.h"
|
||||
#include "histogram_internal.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
std::string getRandomHexColor() {
|
||||
random_device rd; // Èñòî÷íèê ñëó÷àéíûõ ÷èñåë
|
||||
mt19937 gen(rd()); // Ãåíåðàòîð Mersenne Twister
|
||||
std::uniform_int_distribution<> dis(0, 255); // Ðàâíîìåðíîå ðàñïðåäåëåíèå [0, 255]
|
||||
|
||||
int r = dis(gen); // Êðàñíûé
|
||||
int g = dis(gen); // Çåëåíûé
|
||||
int b = dis(gen); // Ñèíèé
|
||||
|
||||
// Ôîðìèðóåì HEX-ñòðîêó
|
||||
std::stringstream hexStream;
|
||||
hexStream << "#"
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << r
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << g
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << b;
|
||||
|
||||
return hexStream.str();
|
||||
}
|
||||
|
||||
void
|
||||
svg_begin(double width, double height) {
|
||||
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||
cout << "<svg ";
|
||||
cout << "width='" << width << "' ";
|
||||
cout << "height='" << height << "' ";
|
||||
cout << "viewBox='0 0 " << width << " " << height << "' ";
|
||||
cout << "xmlns='http://www.w3.org/2000/svg'>\n";
|
||||
}
|
||||
|
||||
void
|
||||
svg_end() {
|
||||
cout << "</svg>\n";
|
||||
}
|
||||
|
||||
void
|
||||
svg_text(double left, double baseline, string text) {
|
||||
cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>" << endl;
|
||||
}
|
||||
|
||||
void svg_rect(double x, double y, double width, double height, string stroke = "black", string fill = "black") {
|
||||
cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << "' stroke='" << stroke << "' fill='" << fill << "' />" << endl;
|
||||
}
|
||||
|
||||
void
|
||||
show_histogram_svg(const vector<size_t> bins) {
|
||||
|
||||
auto mm = *(max_element(bins.begin(), bins.end()));
|
||||
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;
|
||||
auto BLOCK_WIDTH = 10;
|
||||
|
||||
BLOCK_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH) / mm;
|
||||
|
||||
svg_begin(400, 300);
|
||||
|
||||
|
||||
|
||||
double top = 0;
|
||||
for (size_t bin : bins) {
|
||||
const double bin_width = BLOCK_WIDTH * bin;
|
||||
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "grey", getRandomHexColor());
|
||||
top += BIN_HEIGHT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//svg_begin(400, 300);
|
||||
//svg_text(20, 35, to_string(bins[0]));
|
||||
//svg_rect(50, 0, bins[0] * 10, 30, "purple", "red");
|
||||
svg_end();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
12
ProgUit Lab1/text.h
Обычный файл
12
ProgUit Lab1/text.h
Обычный файл
@@ -0,0 +1,12 @@
|
||||
#ifndef TEXT_H_INCLUDED
|
||||
#define TEXT_H_INCLUDED
|
||||
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
||||
void show_histogram_text(std::vector <size_t> bins, size_t bin_count);
|
||||
void show_histogram_svg(const std::vector<size_t> bins);
|
||||
|
||||
|
||||
#endif // TEXT_H_INCLUDED
|
||||
42
ProgUit Lab1/unittest.cpp
Обычный файл
42
ProgUit Lab1/unittest.cpp
Обычный файл
@@ -0,0 +1,42 @@
|
||||
#define DOCTEST_CONFIG_NO_MULTITHREADING
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "doctest.h"
|
||||
#include "histogram_internal.h"
|
||||
#include "histogram_internal.cpp"
|
||||
|
||||
|
||||
TEST_CASE("distinct positive numbers") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({ 1, 2 }, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 2);
|
||||
}
|
||||
TEST_CASE("empty vector") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({}, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 2);
|
||||
}
|
||||
TEST_CASE("you fill so lonly") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({ 1 }, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 2);
|
||||
}
|
||||
TEST_CASE("negative numbers") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({ -1, -2 }, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 2);
|
||||
}
|
||||
TEST_CASE("twins") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({ 1, 1 }, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 2);
|
||||
}
|
||||
37
ProgUit Lab1/unittest.sln
Обычный файл
37
ProgUit Lab1/unittest.sln
Обычный файл
@@ -0,0 +1,37 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.13.35818.85 d17.13
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unittest", "unittest.vcxproj", "{F1F4B159-68BC-4FA5-8930-18F64369A991}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|ARM64 = Debug|ARM64
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|ARM64 = Release|ARM64
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{F1F4B159-68BC-4FA5-8930-18F64369A991}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
||||
{F1F4B159-68BC-4FA5-8930-18F64369A991}.Debug|ARM64.Build.0 = Debug|ARM64
|
||||
{F1F4B159-68BC-4FA5-8930-18F64369A991}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{F1F4B159-68BC-4FA5-8930-18F64369A991}.Debug|x64.Build.0 = Debug|x64
|
||||
{F1F4B159-68BC-4FA5-8930-18F64369A991}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{F1F4B159-68BC-4FA5-8930-18F64369A991}.Debug|x86.Build.0 = Debug|Win32
|
||||
{F1F4B159-68BC-4FA5-8930-18F64369A991}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||
{F1F4B159-68BC-4FA5-8930-18F64369A991}.Release|ARM64.Build.0 = Release|ARM64
|
||||
{F1F4B159-68BC-4FA5-8930-18F64369A991}.Release|x64.ActiveCfg = Release|x64
|
||||
{F1F4B159-68BC-4FA5-8930-18F64369A991}.Release|x64.Build.0 = Release|x64
|
||||
{F1F4B159-68BC-4FA5-8930-18F64369A991}.Release|x86.ActiveCfg = Release|Win32
|
||||
{F1F4B159-68BC-4FA5-8930-18F64369A991}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {7151FF61-0934-460C-AB1C-6ACE5FC5F565}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
Ссылка в новой задаче
Block a user