Родитель
81cafe98fb
Сommit
cbcd4a7ab7
@ -0,0 +1,3 @@
|
||||
/bin
|
||||
/Obj
|
||||
/*.layout
|
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 439 B |
@ -0,0 +1,3 @@
|
||||
10
|
||||
3 3 4 4 4 4 4 5 5 5
|
||||
3
|
@ -0,0 +1 @@
|
||||
{\rtf1}
|
Двоичный файл не отображается.
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -0,0 +1,79 @@
|
||||
#include "histogram.h"
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void find_minmax(const vector<double>& numbers, double& min, double& max)
|
||||
{
|
||||
min = numbers[0];
|
||||
for (auto i = 0; i < numbers.size(); i++)
|
||||
{
|
||||
if (numbers[i] < min)
|
||||
{
|
||||
min = numbers[i];
|
||||
}
|
||||
}
|
||||
|
||||
max = numbers[0];
|
||||
for (auto i = 0; i < numbers.size(); i++)
|
||||
{
|
||||
if (numbers[i] > max)
|
||||
{
|
||||
max = numbers[i];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
vector<size_t> make_histogram(vector<double>& numbers, size_t bin_count)
|
||||
{
|
||||
|
||||
vector<size_t> bins(bin_count);
|
||||
vector<size_t> binss(bin_count);
|
||||
|
||||
double max, min;
|
||||
find_minmax(numbers, min, max);
|
||||
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 lo = min + j * bin_size;
|
||||
auto hi = min + (j + 1) * bin_size;
|
||||
if ((lo <= numbers[i]) && (numbers[i] < hi))
|
||||
{
|
||||
bins[j]++;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
bins[bin_count - 1]++;
|
||||
}
|
||||
}
|
||||
|
||||
int max_count = bins[0];
|
||||
for (size_t i = 0; i < bin_count; i++)
|
||||
{
|
||||
if (bins[i] > max_count)
|
||||
{
|
||||
max_count = bins[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (max_count > 76)
|
||||
{
|
||||
|
||||
for (size_t i = 0; i < bin_count; i++)
|
||||
{
|
||||
int count = bins[i];
|
||||
size_t height = 76 * (static_cast<double>(count) / max_count);
|
||||
bins[i] = height;
|
||||
}
|
||||
}
|
||||
|
||||
return bins;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
#ifndef HISTOGRAM_H_INCLUDED
|
||||
#define HISTOGRAM_H_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
|
||||
std::vector<size_t> make_histogram(std::vector<double>& numbers, size_t bin_count);
|
||||
|
||||
#endif // HISTOGRAM_H_INCLUDED
|
||||
|
@ -0,0 +1,8 @@
|
||||
#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,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="laba3" />
|
||||
<Option pch_mode="2" />
|
||||
<Option compiler="gcc" />
|
||||
<Build>
|
||||
<Target title="Debug">
|
||||
<Option output="bin/Debug/laba3" 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/laba3" 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" />
|
||||
<Add option="-fexceptions" />
|
||||
</Compiler>
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="histogram.h" />
|
||||
<Unit filename="histogram_internal.h" />
|
||||
<Unit filename="main.cpp" />
|
||||
<Unit filename="svg.cpp" />
|
||||
<Unit filename="svg.h" />
|
||||
<Unit filename="text.cpp" />
|
||||
<Unit filename="text.h" />
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
@ -0,0 +1,32 @@
|
||||
# depslib dependency file v1.0
|
||||
1685565176 source:c:\users\Øåñòîâ Äåíèñ\desktop\laba3\histogram.cpp
|
||||
"histogram.h"
|
||||
<vector>
|
||||
|
||||
1685565442 c:\users\Øåñòîâ Äåíèñ\desktop\laba3\histogram.h
|
||||
<vector>
|
||||
|
||||
1685567342 source:c:\users\Øåñòîâ Äåíèñ\desktop\laba3\main.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
"histogram.h"
|
||||
"text.h"
|
||||
"svg.h"
|
||||
|
||||
1685565442 c:\users\Øåñòîâ Äåíèñ\desktop\laba3\text.h
|
||||
<vector>
|
||||
|
||||
1685565360 c:\users\Øåñòîâ Äåíèñ\desktop\laba3\svg.h
|
||||
<vector>
|
||||
|
||||
1685567277 source:c:\users\Øåñòîâ Äåíèñ\desktop\laba3\svg.cpp
|
||||
<vector>
|
||||
<iostream>
|
||||
"svg.h"
|
||||
|
||||
1685567303 source:c:\users\Øåñòîâ Äåíèñ\desktop\laba3\text.cpp
|
||||
"text.h"
|
||||
<vector>
|
||||
<math.h>
|
||||
<iostream>
|
||||
|
@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<File name="histogram.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="202" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="text.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="380" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="svg.cpp" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1332" topLine="28" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<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="732" topLine="22" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="svg.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="156" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="histogram_internal.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="223" topLine="0" />
|
||||
</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="985" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="text.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="176" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
@ -0,0 +1,61 @@
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "svg.h"
|
||||
|
||||
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;
|
||||
const auto MAX_WIDTH = IMAGE_WIDTH-TEXT_WIDTH;
|
||||
|
||||
|
||||
svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT);
|
||||
double top = 0;
|
||||
|
||||
double max_count = bins[0];
|
||||
for (size_t i = 0; i < bins.size(); i++) {
|
||||
if (bins[i] > max_count)
|
||||
max_count = bins[i];
|
||||
}
|
||||
|
||||
|
||||
for (size_t bin : bins) {
|
||||
const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH)*(bin/max_count);
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "red", arr[i]);
|
||||
top += BIN_HEIGHT;
|
||||
}
|
||||
svg_end();
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
#ifndef SVG_H_INCLUDED
|
||||
#define SVG_H_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
|
||||
void show_histogram_svg(const std::vector<size_t>& bins);
|
||||
|
||||
#endif // SVG_H_INCLUDED
|
@ -0,0 +1,28 @@
|
||||
#include "text.h"
|
||||
#include <vector>
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void show_histogram_text(vector <size_t> bins, size_t bin_count)
|
||||
{
|
||||
|
||||
for (size_t i = 0; i < bin_count; i++)
|
||||
{
|
||||
if (bins[i] < 100)
|
||||
{
|
||||
cout<< " ";
|
||||
}
|
||||
if (bins[i] < 10)
|
||||
{
|
||||
cout<< " ";
|
||||
}
|
||||
cout<< bins[i]<<"|";
|
||||
for (size_t j = 0; j < bins[i]; j++)
|
||||
{
|
||||
cout<< "*";
|
||||
}
|
||||
cout<< "\n";
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
#ifndef TEXT_H_INCLUDED
|
||||
#define TEXT_H_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
void show_histogram_text(std::vector <size_t> bins, size_t bin_count);
|
||||
|
||||
|
||||
#endif // TEXT_H_INCLUDED
|
@ -0,0 +1,39 @@
|
||||
<?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>
|
||||
<Unit filename="doctest.h" />
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="unittest.cpp" />
|
||||
<Extensions />
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
@ -0,0 +1,28 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
TEST_CASE("odinakovie") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({1, 1}, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("distinct negative numbers") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({-2, -1}, min, max);
|
||||
CHECK(min == -2);
|
||||
CHECK(max == -1);
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
# depslib dependency file v1.0
|
||||
1685565360 source:c:\users\Øåñòîâ Äåíèñ\desktop\laba3\unittest.cpp
|
||||
"doctest.h"
|
||||
"histogram_internal.h"
|
||||
|
||||
1685565129 c:\users\Øåñòîâ Äåíèñ\desktop\laba3\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>
|
||||
|
||||
1685565176 c:\users\Øåñòîâ Äåíèñ\desktop\laba3\histogram_internal.h
|
||||
<vector>
|
||||
|
||||
1685565176 source:c:\users\Øåñòîâ Äåíèñ\desktop\laba3\histogram.cpp
|
||||
"histogram.h"
|
||||
<vector>
|
||||
|
||||
1685565442 c:\users\Øåñòîâ Äåíèñ\desktop\laba3\histogram.h
|
||||
<vector>
|
||||
|
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<File name="unittest.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="334" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="doctest.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
Загрузка…
Ссылка в новой задаче