Родитель
4574a4c976
Сommit
0f65ce7b08
@ -0,0 +1,3 @@
|
||||
2|**
|
||||
5|*****
|
||||
3|***
|
@ -0,0 +1,3 @@
|
||||
2|**
|
||||
5|*****
|
||||
3|***
|
@ -0,0 +1,3 @@
|
||||
10
|
||||
4 4 3 5 3 4 5 5 4 4
|
||||
3
|
@ -0,0 +1,3 @@
|
||||
9|*********
|
||||
33|*********************************
|
||||
100|****************************************************************************************************
|
@ -0,0 +1,5 @@
|
||||
142
|
||||
1 1 1 1 1 1 1 1 1
|
||||
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
|
||||
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
|
||||
3
|
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 433 B |
@ -0,0 +1,3 @@
|
||||
10
|
||||
3 3 4 4 4 4 4 5 5 5
|
||||
3
|
@ -0,0 +1,2 @@
|
||||
lab01.exe < 01-example.input.txt > 01-example.actual.txt 2>NUL
|
||||
fc /N 01-example.actual.txt 01-example.expected.txt || pause
|
@ -0,0 +1,2 @@
|
||||
lab01.exe < 02-alignment.input.txt > 01-example.actual.txt 2>NUL
|
||||
fc /N 01-example.actual.txt 02-alignment.expected.txt || pause
|
Двоичный файл не отображается.
@ -0,0 +1,58 @@
|
||||
#include "histogram.h"
|
||||
#include "histogram_internal.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void
|
||||
find_minmax(const 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vector<size_t>
|
||||
make_histogram(const vector<double>& numbers, size_t bin_count)
|
||||
{
|
||||
vector<size_t> bins(bin_count);
|
||||
double min, max;
|
||||
find_minmax(numbers, min, max);
|
||||
|
||||
double bin_size = (max - min) / bin_count;
|
||||
|
||||
size_t max_count = 0;
|
||||
|
||||
for (size_t i = 0; i < numbers.size(); i++)
|
||||
{
|
||||
bool found = false;
|
||||
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
|
||||
{
|
||||
auto lo = min + j * bin_size;
|
||||
auto hi = min + (j + 1) * bin_size;
|
||||
if ((lo <= numbers[i]) && (numbers[i] < hi))
|
||||
{
|
||||
bins[j]++;
|
||||
if (bins[j] > max_count)
|
||||
{
|
||||
max_count = bins[j];
|
||||
}
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
bins[bin_count - 1]++;
|
||||
}
|
||||
}
|
||||
return bins;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
#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
|
@ -0,0 +1,9 @@
|
||||
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
|
||||
void
|
||||
find_minmax(const std::vector<double>& numbers, double& min, double& max);
|
||||
|
||||
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
@ -0,0 +1,29 @@
|
||||
# depslib dependency file v1.0
|
||||
1746385589 source:c:\users\krivo\desktop\lab03\main.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
"histogram.h"
|
||||
"text.h"
|
||||
"svg.h"
|
||||
|
||||
1746381170 c:\users\krivo\desktop\lab03\histogram.h
|
||||
<vector>
|
||||
|
||||
1746383913 source:c:\users\krivo\desktop\lab03\histogram.cpp
|
||||
"histogram.h"
|
||||
"histogram_internal.h"
|
||||
|
||||
1746381509 c:\users\krivo\desktop\lab03\text.h
|
||||
<vector>
|
||||
|
||||
1746382043 source:c:\users\krivo\desktop\lab03\text.cpp
|
||||
"text.h"
|
||||
<iostream>
|
||||
|
||||
1746383746 c:\users\krivo\desktop\lab03\histogram_internal.h
|
||||
<vector>
|
||||
|
||||
1746386429 c:\users\krivo\desktop\lab03\svg.h
|
||||
<vector>
|
||||
<string>
|
||||
|
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="623" topLine="10" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="histogram.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="124" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="text.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="52" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="text.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="histogram_internal.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="205" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="svg.cpp" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="40" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="histogram.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
Двоичный файл не отображается.
Двоичный файл не отображается.
@ -0,0 +1,3 @@
|
||||
10
|
||||
3 3 4 4 4 4 4 5 5 5
|
||||
3
|
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
@ -0,0 +1,67 @@
|
||||
#include "svg.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
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>";
|
||||
}
|
||||
|
||||
void
|
||||
svg_rect(double x, double y, double width, double height, string stroke, string fill)
|
||||
{
|
||||
cout << "<rect x='" << x << "' y='" << y << "' width='" << width
|
||||
<< "' height='" << height << "' stroke='" << stroke << "' fill='" << fill << " '/>";
|
||||
}
|
||||
|
||||
void
|
||||
show_histogram_svg(const vector<size_t>& bins)
|
||||
{
|
||||
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;
|
||||
|
||||
svg_begin(400, 300);
|
||||
double top = 0;
|
||||
|
||||
for (size_t bin : bins)
|
||||
{
|
||||
const double bin_width = BLOCK_WIDTH * bin;
|
||||
if(bin_width> IMAGE_WIDTH)
|
||||
{
|
||||
const double bin_width= IMAGE_WIDTH - TEXT_WIDTH;
|
||||
}
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "light blue");
|
||||
top += BIN_HEIGHT;
|
||||
}
|
||||
|
||||
//svg_text(20, 20, to_string(bins[0]));
|
||||
//svg_rect(50, 0, bins[0] * 10, 30);
|
||||
svg_end();
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
#ifndef SVG_H_INCLUDED
|
||||
#define SVG_H_INCLUDED
|
||||
#include <vector>
|
||||
#include<string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void
|
||||
svg_begin(double width, double height);
|
||||
|
||||
void
|
||||
svg_end();
|
||||
|
||||
void
|
||||
svg_text(double left, double baseline, string text);
|
||||
|
||||
void
|
||||
svg_rect(double x, double y, double width, double height, string stroke = "black", string fill = "black");
|
||||
|
||||
void
|
||||
show_histogram_svg(const vector<size_t>& bins);
|
||||
|
||||
#endif // SVG_H_INCLUDED
|
@ -0,0 +1,48 @@
|
||||
#include "text.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void
|
||||
static printspace (int number)
|
||||
{
|
||||
if (number < 10) cout << " ";
|
||||
else if (number < 100) cout << " ";
|
||||
}
|
||||
|
||||
void
|
||||
show_histogram_text(const vector<size_t>& bins, size_t bin_count)
|
||||
{
|
||||
size_t max_count = 0;
|
||||
for (int i = 0; i < bins.size(); i++)
|
||||
{
|
||||
if (bins[i] > max_count) max_count = bins[i];
|
||||
}
|
||||
if (max_count <= 76)
|
||||
{
|
||||
for (size_t i = 0; i < bin_count; i++)
|
||||
{
|
||||
printspace(bins[i]);
|
||||
cout << bins[i] << "|";
|
||||
for (size_t j = 0; j < bins[i]; j++)
|
||||
{
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < bin_count; i++)
|
||||
{
|
||||
size_t height = 76 * (static_cast<double>(bins[i]) / max_count);
|
||||
printspace(bins[i]);
|
||||
cout << bins[i] << "|";
|
||||
for (size_t j = 0; j < height; j++)
|
||||
{
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
#ifndef TEXT_H_INCLUDED
|
||||
#define TEXT_H_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
|
||||
void
|
||||
show_histogram_text(const std::vector<size_t>& bins, size_t bin_count);
|
||||
|
||||
#endif // TEXT_H_INCLUDED
|
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="unittest" />
|
||||
<Option pch_mode="2" />
|
||||
<Option compiler="gcc" />
|
||||
<Build>
|
||||
<Target title="Debug">
|
||||
<Option output="bin/Debug/unittest" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Debug/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-g" />
|
||||
</Compiler>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
<Option output="bin/Release/unittest" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Release/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-O2" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-s" />
|
||||
</Linker>
|
||||
</Target>
|
||||
</Build>
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
</Compiler>
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
@ -0,0 +1,12 @@
|
||||
#define DOCTEST_CONFIG_NO_MULTITHREADING
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "doctest.h"
|
||||
#include "histogram_internal.h"
|
||||
|
||||
TEST_CASE("distinct positive numbers") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({1, 2}, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 2);
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
# depslib dependency file v1.0
|
||||
1746383500 source:c:\users\krivo\desktop\lab03\unittest.cpp
|
||||
"doctest.h"
|
||||
"histogram_internal.h"
|
||||
|
||||
1746383051 c:\users\krivo\desktop\lab03\doctest.h
|
||||
<signal.h>
|
||||
<ciso646>
|
||||
<cstddef>
|
||||
<ostream>
|
||||
<istream>
|
||||
<type_traits>
|
||||
"doctest_fwd.h"
|
||||
<ctime>
|
||||
<cmath>
|
||||
<climits>
|
||||
<math.h>
|
||||
<new>
|
||||
<cstdio>
|
||||
<cstdlib>
|
||||
<cstring>
|
||||
<limits>
|
||||
<utility>
|
||||
<fstream>
|
||||
<sstream>
|
||||
<iostream>
|
||||
<algorithm>
|
||||
<iomanip>
|
||||
<vector>
|
||||
<atomic>
|
||||
<mutex>
|
||||
<set>
|
||||
<map>
|
||||
<unordered_set>
|
||||
<exception>
|
||||
<stdexcept>
|
||||
<csignal>
|
||||
<cfloat>
|
||||
<cctype>
|
||||
<cstdint>
|
||||
<string>
|
||||
<sys/types.h>
|
||||
<unistd.h>
|
||||
<sys/sysctl.h>
|
||||
<AfxWin.h>
|
||||
<windows.h>
|
||||
<io.h>
|
||||
<sys/time.h>
|
||||
<unistd.h>
|
||||
|
||||
1746383746 c:\users\krivo\desktop\lab03\histogram_internal.h
|
||||
<vector>
|
||||
|
||||
1746383913 source:c:\users\krivo\desktop\lab03\histogram.cpp
|
||||
"histogram.h"
|
||||
"histogram_internal.h"
|
||||
|
||||
1746381170 c:\users\krivo\desktop\lab03\histogram.h
|
||||
<vector>
|
||||
|
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
</CodeBlocks_layout_file>
|
Загрузка…
Ссылка в новой задаче