Родитель
6e9139fe35
Сommit
53f1e4e9a8
@ -0,0 +1,82 @@
|
|||||||
|
# depslib dependency file v1.0
|
||||||
|
1713791550 source:c:\users\u113-02\desktop\hehehe\main.cpp
|
||||||
|
<vector>
|
||||||
|
<iostream>
|
||||||
|
<cmath>
|
||||||
|
|
||||||
|
1714330914 source:e:\hehehe\main.cpp
|
||||||
|
<vector>
|
||||||
|
<iostream>
|
||||||
|
<cmath>
|
||||||
|
|
||||||
|
1714921863 source:c:\users\nick\desktop\hehehe\main.cpp
|
||||||
|
<vector>
|
||||||
|
<iostream>
|
||||||
|
<cmath>
|
||||||
|
"histogram.h"
|
||||||
|
"svg.h"
|
||||||
|
"text.h"
|
||||||
|
|
||||||
|
1714861965 c:\users\nick\desktop\hehehe\histogram.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1714862011 source:c:\users\nick\desktop\hehehe\histogram.cpp
|
||||||
|
"histogram.h"
|
||||||
|
<vector>
|
||||||
|
<iostream>
|
||||||
|
|
||||||
|
1714919929 source:c:\users\nick\desktop\hehehe\svg.cpp
|
||||||
|
<iostream>
|
||||||
|
<vector>
|
||||||
|
<string>
|
||||||
|
"svg.h"
|
||||||
|
|
||||||
|
1714919958 c:\users\nick\desktop\hehehe\svg.h
|
||||||
|
<vector>
|
||||||
|
<string>
|
||||||
|
|
||||||
|
1714921819 c:\users\nick\desktop\hehehe\text.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1714921889 source:c:\users\nick\desktop\hehehe\text.cpp
|
||||||
|
"text.h"
|
||||||
|
"svg.h"
|
||||||
|
<string>
|
||||||
|
<iostream>
|
||||||
|
|
||||||
|
1714862012 source:c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\histogram.cpp
|
||||||
|
"histogram.h"
|
||||||
|
<vector>
|
||||||
|
<iostream>
|
||||||
|
|
||||||
|
1714861966 c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\histogram.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1714997928 source:c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\main.cpp
|
||||||
|
<vector>
|
||||||
|
<iostream>
|
||||||
|
<cmath>
|
||||||
|
"histogram.h"
|
||||||
|
"svg.h"
|
||||||
|
"text.h"
|
||||||
|
|
||||||
|
1714997791 c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\svg.h
|
||||||
|
<vector>
|
||||||
|
<string>
|
||||||
|
|
||||||
|
1714996911 c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\text.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1714997791 source:c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\text.cpp
|
||||||
|
"text.h"
|
||||||
|
"svg.h"
|
||||||
|
<string>
|
||||||
|
<iostream>
|
||||||
|
"text.h"
|
||||||
|
|
||||||
|
1714997285 source:c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\svg.cpp
|
||||||
|
<iostream>
|
||||||
|
<vector>
|
||||||
|
<string>
|
||||||
|
"svg.h"
|
||||||
|
|
@ -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="113" topLine="58" />
|
||||||
|
</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="0" 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="1097" topLine="20" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="text.cpp" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="736" topLine="18" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="svg.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="948" topLine="18" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="svg.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="0" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<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="0" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
</CodeBlocks_layout_file>
|
@ -0,0 +1,43 @@
|
|||||||
|
#include "histogram.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<double>
|
||||||
|
make_histogram(const std::vector<double>& numbers, size_t bin_count) {
|
||||||
|
vector<double> bins(bin_count);
|
||||||
|
|
||||||
|
double min = 0, max = 0;
|
||||||
|
find_minmax(numbers, min, max);
|
||||||
|
|
||||||
|
double bin_size = (max - min) / bin_count;
|
||||||
|
for (int i = 0; i < numbers.size(); i++) {
|
||||||
|
bool found = false;
|
||||||
|
for (int 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]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bins;
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
std::vector<double>
|
||||||
|
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 <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#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 std::vector<double>& 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);
|
||||||
|
|
||||||
|
double max_count = (bins[0] * BLOCK_WIDTH);
|
||||||
|
for (double bin : bins) {
|
||||||
|
if ((bin * BLOCK_WIDTH) > max_count) {
|
||||||
|
max_count = (bin * BLOCK_WIDTH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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, "red", "#00ffff");
|
||||||
|
top += 2*BIN_HEIGHT;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
void show_histogram_svg(const std::vector<double>& bins);
|
||||||
|
|
@ -0,0 +1,42 @@
|
|||||||
|
#include "text.h"
|
||||||
|
#include "svg.h"
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include "text.h"
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void show_histogram_text (const std::vector<double>& bins, size_t MAX_ASTERISK, 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) {
|
||||||
|
cout << " " << bins[i] << "|";
|
||||||
|
}
|
||||||
|
else if (bins[i] < 100) {
|
||||||
|
cout << " " << bins[i] << "|";
|
||||||
|
}
|
||||||
|
else if (bins[i] < 1000) {
|
||||||
|
cout << bins[i] << "|";
|
||||||
|
|
||||||
|
}
|
||||||
|
for (int j = 0; j < int(bins[i] * k); j++)
|
||||||
|
{
|
||||||
|
cout << "*";
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
void show_histogram_text(const std::vector<double>& bins, size_t MAX_ASTERISK, size_t bin_count);
|
||||||
|
|
@ -0,0 +1,41 @@
|
|||||||
|
<?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="histogram.cpp" />
|
||||||
|
<Unit filename="histogram_internal.h" />
|
||||||
|
<Unit filename="unittest.cpp" />
|
||||||
|
<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,121 @@
|
|||||||
|
# depslib dependency file v1.0
|
||||||
|
1714862011 source:c:\users\nick\desktop\hehehe\histogram.cpp
|
||||||
|
"histogram.h"
|
||||||
|
<vector>
|
||||||
|
<iostream>
|
||||||
|
|
||||||
|
1714861965 c:\users\nick\desktop\hehehe\histogram.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1714917108 source:c:\users\nick\desktop\hehehe\unittest.cpp
|
||||||
|
"doctest.h"
|
||||||
|
"histogram_internal.h"
|
||||||
|
|
||||||
|
1714916946 c:\users\nick\desktop\hehehe\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>
|
||||||
|
|
||||||
|
1714862096 c:\users\nick\desktop\hehehe\histogram_internal.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1714862012 source:c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\histogram.cpp
|
||||||
|
"histogram.h"
|
||||||
|
<vector>
|
||||||
|
<iostream>
|
||||||
|
|
||||||
|
1714861966 c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\histogram.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1714917110 source:c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\unittest.cpp
|
||||||
|
"doctest.h"
|
||||||
|
"histogram_internal.h"
|
||||||
|
|
||||||
|
1714916948 c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\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>
|
||||||
|
|
||||||
|
1714862098 c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\histogram_internal.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>
|
Загрузка…
Ссылка в новой задаче