Сравнить коммиты
10 Коммитов
41b5ffe3cd
...
main
| Автор | SHA1 | Дата | |
|---|---|---|---|
| 703a7496c9 | |||
| fd47eaab64 | |||
| d11a01d781 | |||
| 40cc4f7fe1 | |||
| 8296a5cc4e | |||
| 82a8d9f469 | |||
| 72c1e547fe | |||
| 133ecfbbb6 | |||
| 454cc7cfe9 | |||
| 7d40417204 |
3
.gitignore
поставляемый
Обычный файл
3
.gitignore
поставляемый
Обычный файл
@@ -0,0 +1,3 @@
|
|||||||
|
/bin
|
||||||
|
/obj
|
||||||
|
/curl
|
||||||
7106
doctest.h
Обычный файл
7106
doctest.h
Обычный файл
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
44
histogram.cpp
Обычный файл
44
histogram.cpp
Обычный файл
@@ -0,0 +1,44 @@
|
|||||||
|
#include "histogram.h"
|
||||||
|
#include "histogram_internal.h"
|
||||||
|
#include <vector>
|
||||||
|
using std::vector;
|
||||||
|
void find_minmax(const vector<double>& numbers, double& min, double& max) {
|
||||||
|
if (numbers.empty())
|
||||||
|
{
|
||||||
|
min = 0;
|
||||||
|
max = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
max = numbers[0];
|
||||||
|
min = 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) {
|
||||||
|
std::vector<size_t> bins(bin_count, 0);
|
||||||
|
|
||||||
|
double min, max;
|
||||||
|
find_minmax(numbers, min, max);
|
||||||
|
|
||||||
|
double bin_size = (max - min) / bin_count;
|
||||||
|
|
||||||
|
for (double number : numbers) {
|
||||||
|
bool found = false;
|
||||||
|
for (size_t j = 0; (j < bin_count - 1) && !found; j++) {
|
||||||
|
double lo = min + j * bin_size;
|
||||||
|
double hi = min + (j + 1) * bin_size;
|
||||||
|
if ((lo <= number) && (number < hi)) {
|
||||||
|
bins[j]++;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
bins[bin_count - 1]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return bins;
|
||||||
|
}
|
||||||
10
histogram.h
Обычный файл
10
histogram.h
Обычный файл
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef HISTOGRAM_H_INCLUDED
|
||||||
|
#define HISTOGRAM_H_INCLUDED
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
using std::vector;
|
||||||
|
std::vector<size_t>
|
||||||
|
make_histogram(const std::vector<double>& numbers, size_t bin_count);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // HISTOGRAM_H_INCLUDED
|
||||||
8
histogram_internal.h
Обычный файл
8
histogram_internal.h
Обычный файл
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
|
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
|
#include <vector>
|
||||||
|
using std::vector;
|
||||||
|
void find_minmax(const std::vector<double>& numbers, double& min, double& max);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
@@ -32,6 +32,11 @@
|
|||||||
<Add option="-Wall" />
|
<Add option="-Wall" />
|
||||||
<Add option="-fexceptions" />
|
<Add option="-fexceptions" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
|
<Unit filename=".gitignore" />
|
||||||
|
<Unit filename="histogram.cpp" />
|
||||||
|
<Unit filename="histogram.h">
|
||||||
|
<Option target="<{~None~}>" />
|
||||||
|
</Unit>
|
||||||
<Unit filename="main.cpp" />
|
<Unit filename="main.cpp" />
|
||||||
<Extensions>
|
<Extensions>
|
||||||
<lib_finder disable_auto="1" />
|
<lib_finder disable_auto="1" />
|
||||||
|
|||||||
176
laba1.depend
Обычный файл
176
laba1.depend
Обычный файл
@@ -0,0 +1,176 @@
|
|||||||
|
# depslib dependency file v1.0
|
||||||
|
1748850108 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\main.cpp
|
||||||
|
<iostream>
|
||||||
|
<vector>
|
||||||
|
"histogram.h"
|
||||||
|
"text.h"
|
||||||
|
"svg.h"
|
||||||
|
<curl/curl.h>
|
||||||
|
|
||||||
|
1748386910 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\histogram.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1748730472 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\text.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1748808306 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\text.cpp
|
||||||
|
"text.h"
|
||||||
|
<iostream>
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1748392747 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\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>
|
||||||
|
|
||||||
|
1748392232 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\histogram_internal.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1748811805 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\svg.cpp
|
||||||
|
"svg.h"
|
||||||
|
<iostream>
|
||||||
|
|
||||||
|
1748810901 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\svg.h
|
||||||
|
<vector>
|
||||||
|
<cstddef>
|
||||||
|
|
||||||
|
1748808114 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\histogram.cpp
|
||||||
|
"histogram.h"
|
||||||
|
"histogram_internal.h"
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1748808114 D
|
||||||
|
|
||||||
|
1748875465 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\histogram.cpp
|
||||||
|
"histogram.h"
|
||||||
|
"histogram_internal.h"
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1748386910 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\histogram.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1748392232 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\histogram_internal.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1749630788 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\main.cpp
|
||||||
|
<iostream>
|
||||||
|
<vector>
|
||||||
|
<string>
|
||||||
|
"histogram.h"
|
||||||
|
"text.h"
|
||||||
|
"svg.h"
|
||||||
|
"histogram_internal.h"
|
||||||
|
|
||||||
|
1748730472 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\text.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1749627429 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\svg.h
|
||||||
|
<vector>
|
||||||
|
<cstddef>
|
||||||
|
|
||||||
|
1748808306 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\text.cpp
|
||||||
|
"text.h"
|
||||||
|
<iostream>
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1749628551 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\svg.cpp
|
||||||
|
"svg.h"
|
||||||
|
<iostream>
|
||||||
|
|
||||||
|
1748876656
|
||||||
|
|
||||||
|
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\curl.h
|
||||||
|
"curlver.h"
|
||||||
|
"system.h"
|
||||||
|
<stdio.h>
|
||||||
|
<limits.h>
|
||||||
|
<sys/param.h>
|
||||||
|
<sys/types.h>
|
||||||
|
<time.h>
|
||||||
|
<winsock2.h>
|
||||||
|
<ws2tcpip.h>
|
||||||
|
<sys/select.h>
|
||||||
|
<sys/socket.h>
|
||||||
|
<sys/time.h>
|
||||||
|
"easy.h"
|
||||||
|
"multi.h"
|
||||||
|
"urlapi.h"
|
||||||
|
"options.h"
|
||||||
|
"header.h"
|
||||||
|
"websockets.h"
|
||||||
|
"mprintf.h"
|
||||||
|
"typecheck-gcc.h"
|
||||||
|
|
||||||
|
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\curlver.h
|
||||||
|
|
||||||
|
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\system.h
|
||||||
|
<ConditionalMacros.h>
|
||||||
|
<inttypes.h>
|
||||||
|
<inttypes.h>
|
||||||
|
<sys/types.h>
|
||||||
|
<sys/socket.h>
|
||||||
|
<sys/poll.h>
|
||||||
|
|
||||||
|
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\easy.h
|
||||||
|
|
||||||
|
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\multi.h
|
||||||
|
"curl.h"
|
||||||
|
|
||||||
|
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\urlapi.h
|
||||||
|
"curl.h"
|
||||||
|
|
||||||
|
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\options.h
|
||||||
|
|
||||||
|
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\header.h
|
||||||
|
|
||||||
|
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\websockets.h
|
||||||
|
|
||||||
|
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\mprintf.h
|
||||||
|
<stdarg.h>
|
||||||
|
<stdio.h>
|
||||||
|
"curl.h"
|
||||||
|
|
||||||
|
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\typecheck-gcc.h
|
||||||
|
|
||||||
|
1748849797 c4f7fe14afe3358e7b9d7bc3578a9c995ebd7
|
||||||
|
|
||||||
0
laba1.exe
Обычный файл
0
laba1.exe
Обычный файл
20
laba1.layout
Обычный файл
20
laba1.layout
Обычный файл
@@ -0,0 +1,20 @@
|
|||||||
|
<?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="893" topLine="30" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="histogram.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="193" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name=".gitignore" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="10" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
</CodeBlocks_layout_file>
|
||||||
0
laba1/bin/Debug/laba1.exe
Обычный файл
0
laba1/bin/Debug/laba1.exe
Обычный файл
0
laba1/bin/Debug/marks.svg
Обычный файл
0
laba1/bin/Debug/marks.svg
Обычный файл
38
laba1/laba1.cbp
Обычный файл
38
laba1/laba1.cbp
Обычный файл
@@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_project_file>
|
||||||
|
<FileVersion major="1" minor="6" />
|
||||||
|
<Project>
|
||||||
|
<Option title="laba1" />
|
||||||
|
<Option pch_mode="2" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Build>
|
||||||
|
<Target title="Debug">
|
||||||
|
<Option output="bin/Debug/laba1" 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/laba1" 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="main.cpp" />
|
||||||
|
<Extensions />
|
||||||
|
</Project>
|
||||||
|
</CodeBlocks_project_file>
|
||||||
25
laba1/laba1.depend
Обычный файл
25
laba1/laba1.depend
Обычный файл
@@ -0,0 +1,25 @@
|
|||||||
|
# depslib dependency file v1.0
|
||||||
|
1748387373 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\histogram.cpp
|
||||||
|
"histogram.h"
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1748386910 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\histogram.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1748388937 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\main.cpp
|
||||||
|
<iostream>
|
||||||
|
<vector>
|
||||||
|
"histogram.h"
|
||||||
|
"text.h"
|
||||||
|
|
||||||
|
1748388603 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\text.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1584205420 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\laba1\main.cpp
|
||||||
|
<iostream>
|
||||||
|
|
||||||
|
1748391445 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\text.cpp
|
||||||
|
"text.h"
|
||||||
|
<iostream>
|
||||||
|
<vector>
|
||||||
|
|
||||||
5
laba1/laba1.layout
Обычный файл
5
laba1/laba1.layout
Обычный файл
@@ -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>
|
||||||
Двоичные данные
laba1/obj/Debug/histogram.o
Обычный файл
Двоичные данные
laba1/obj/Debug/histogram.o
Обычный файл
Двоичный файл не отображается.
Двоичные данные
laba1/obj/Debug/main.o
Обычный файл
Двоичные данные
laba1/obj/Debug/main.o
Обычный файл
Двоичный файл не отображается.
Двоичные данные
laba1/obj/Debug/text.o
Обычный файл
Двоичные данные
laba1/obj/Debug/text.o
Обычный файл
Двоичный файл не отображается.
121
main.cpp
121
main.cpp
@@ -1,112 +1,39 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include "histogram.h"
|
||||||
|
#include "text.h"
|
||||||
|
#include "svg.h"
|
||||||
|
#include "histogram_internal.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main()
|
struct Input {
|
||||||
{
|
vector<double> numbers;
|
||||||
const size_t SCREEN_WIDTH = 80;
|
size_t bin_count;
|
||||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
};
|
||||||
|
|
||||||
|
Input input_data() {
|
||||||
|
Input in;
|
||||||
size_t number_count;
|
size_t number_count;
|
||||||
|
|
||||||
cerr << "Enter number count: ";
|
cerr << "Enter number count: ";
|
||||||
cin >> number_count;
|
cin >> number_count;
|
||||||
vector<double> numbers(number_count);
|
in.numbers.resize(number_count);
|
||||||
|
|
||||||
|
cerr << "Enter numbers: ";
|
||||||
cerr << "Enter number masiv: ";
|
for (size_t i = 0; i < number_count; i++) {
|
||||||
for (size_t i=0; i<number_count; i++)
|
cin >> in.numbers[i];
|
||||||
{
|
|
||||||
cin >> numbers[i];
|
|
||||||
}
|
}
|
||||||
size_t bin_count;
|
|
||||||
cerr << "Enter bin count: ";
|
cerr << "Enter bin count: ";
|
||||||
cin >> bin_count;
|
cin >> in.bin_count; // You were missing this line to read bin_count
|
||||||
|
|
||||||
vector<size_t> bins(bin_count);
|
return in;
|
||||||
double min = numbers[0];
|
|
||||||
double max = numbers[0];
|
|
||||||
for (double x : numbers)
|
|
||||||
{
|
|
||||||
if (x < min)
|
|
||||||
{
|
|
||||||
min = x;
|
|
||||||
}
|
|
||||||
else if (x > max)
|
|
||||||
{
|
|
||||||
max = x;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double bin_size = (max - min) / bin_count;
|
int main() {
|
||||||
|
auto in = input_data();
|
||||||
for (size_t i = 0; i < number_count; i++)
|
auto bins = make_histogram(in.numbers, in.bin_count); // Added second argument
|
||||||
{
|
show_histogram_svg(bins);
|
||||||
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]++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
size_t Maxbins = 0;
|
|
||||||
|
|
||||||
|
|
||||||
for (size_t i = 0; i < bin_count; i++)
|
|
||||||
{
|
|
||||||
if (bins[i] > Maxbins)
|
|
||||||
{
|
|
||||||
Maxbins = bins[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const size_t MAX_HEIGHT = 76;
|
|
||||||
|
|
||||||
if (Maxbins <= MAX_HEIGHT)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < bin_count; i++)
|
|
||||||
{
|
|
||||||
if (bins[i] < 10)
|
|
||||||
{
|
|
||||||
cout << " ";
|
|
||||||
}
|
|
||||||
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 = static_cast<size_t>(MAX_HEIGHT * (static_cast<double>(bins[i]) / Maxbins));
|
|
||||||
|
|
||||||
if (bins[i] < 100)
|
|
||||||
{
|
|
||||||
cout << " ";
|
|
||||||
}
|
|
||||||
if (bins[i] < 10)
|
|
||||||
{
|
|
||||||
cout << " ";
|
|
||||||
}
|
|
||||||
cout << bins[i] << "|";
|
|
||||||
for (size_t j = 0; j < height; j++)
|
|
||||||
{
|
|
||||||
cout << "*";
|
|
||||||
}
|
|
||||||
cout << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Двоичные данные
main.o
Обычный файл
Двоичные данные
main.o
Обычный файл
Двоичный файл не отображается.
66
svg.cpp
Обычный файл
66
svg.cpp
Обычный файл
@@ -0,0 +1,66 @@
|
|||||||
|
#include "svg.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <numeric>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void svg_begin(double width, double height) {
|
||||||
|
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||||
|
cout << "<svg width='" << width << "' height='" << height << "' "
|
||||||
|
<< "viewBox='0 0 " << width << " " << height << "' "
|
||||||
|
<< "xmlns='http://www.w3.org/2000/svg'>\n";
|
||||||
|
|
||||||
|
// Ñòèëè äëÿ SVG
|
||||||
|
cout << "<style>\n"
|
||||||
|
<< " .bar-green { fill: #4CAF50; stroke: #388E3C; stroke-width: 1; }\n"
|
||||||
|
<< " .bar-red { fill: #F44336; stroke: #D32F2F; stroke-width: 1; }\n"
|
||||||
|
<< " .text { font: 12px sans-serif; fill: #333; }\n"
|
||||||
|
<< "</style>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void svg_end() {
|
||||||
|
cout << "</svg>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void svg_text(double left, double baseline, string text) {
|
||||||
|
cout << "<text class='text' x='" << left << "' y='" << baseline << "'>"
|
||||||
|
<< text << "</text>";
|
||||||
|
}
|
||||||
|
|
||||||
|
void svg_rect(double x, double y, double width, double height, bool is_above_average) {
|
||||||
|
string bar_class = is_above_average ? "bar-red" : "bar-green";
|
||||||
|
cout << "<rect class='" << bar_class << "' x='" << x << "' y='" << y
|
||||||
|
<< "' width='" << width << "' height='" << height << "' />";
|
||||||
|
}
|
||||||
|
|
||||||
|
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 MAX_WIDTH = IMAGE_WIDTH - TEXT_WIDTH;
|
||||||
|
|
||||||
|
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||||
|
|
||||||
|
double top = 0;
|
||||||
|
size_t max_count = 0;
|
||||||
|
for (size_t count : bins) {
|
||||||
|
if (count > max_count) max_count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Âû÷èñëÿåì ñðåäíþþ âûñîòó ñòîëáöà
|
||||||
|
double average_height = 0;
|
||||||
|
if (!bins.empty()) {
|
||||||
|
average_height = accumulate(bins.begin(), bins.end(), 0.0) / bins.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t bin : bins) {
|
||||||
|
const double bin_width = MAX_WIDTH * (static_cast<double>(bin) / max_count);
|
||||||
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||||
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, bin > average_height);
|
||||||
|
top += BIN_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
svg_end();
|
||||||
|
}
|
||||||
9
svg.h
Обычный файл
9
svg.h
Обычный файл
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef SVG_H_INCLUDED
|
||||||
|
#define SVG_H_INCLUDED
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
void show_histogram_svg(const std::vector<size_t>& bins);
|
||||||
|
|
||||||
|
#endif
|
||||||
37
text.cpp
Обычный файл
37
text.cpp
Обычный файл
@@ -0,0 +1,37 @@
|
|||||||
|
#include "text.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using std::vector;
|
||||||
|
const size_t SCREEN_WIDTH = 80;
|
||||||
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||||
|
// Âûâîä ãèñòîãðàììû
|
||||||
|
void show_histogram_text(const std::vector<size_t>& bins) {
|
||||||
|
size_t max_bin_count = 0;
|
||||||
|
for (size_t bin : bins) {
|
||||||
|
if (bin > max_bin_count) {
|
||||||
|
max_bin_count = bin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (max_bin_count <= MAX_ASTERISK) {
|
||||||
|
for (size_t bin : bins) {
|
||||||
|
if (bin < 10) std::cout << " ";
|
||||||
|
std::cout << " " << bin << "|";
|
||||||
|
for (size_t j = 0; j < bin; j++) {
|
||||||
|
std::cout << "*";
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (size_t bin : bins) {
|
||||||
|
size_t height = static_cast<size_t>(MAX_ASTERISK * (static_cast<double>(bin) / max_bin_count));
|
||||||
|
if (bin < 100) std::cout << " ";
|
||||||
|
if (bin < 10) std::cout << " ";
|
||||||
|
std::cout << bin << "|";
|
||||||
|
for (size_t j = 0; j < height; j++) {
|
||||||
|
std::cout << "*";
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
text.h
Обычный файл
9
text.h
Обычный файл
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef TEXT_H_INCLUDED
|
||||||
|
#define TEXT_H_INCLUDED
|
||||||
|
#include <vector>
|
||||||
|
using std::vector;
|
||||||
|
|
||||||
|
void show_histogram_text(const std::vector<size_t>& bins);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // TEXT_H_INCLUDED
|
||||||
38
unittest.cbp
Обычный файл
38
unittest.cbp
Обычный файл
@@ -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>
|
||||||
62
unittest.cpp
Обычный файл
62
unittest.cpp
Обычный файл
@@ -0,0 +1,62 @@
|
|||||||
|
#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("distinct negative numbers"){
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({-1, -2}, min, max);
|
||||||
|
CHECK(min == -2);
|
||||||
|
CHECK(max == -1);
|
||||||
|
}
|
||||||
|
TEST_CASE("vector of the same elements"){
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({3,3,3}, min, max);
|
||||||
|
CHECK(min == 3);
|
||||||
|
CHECK(max == 3);
|
||||||
|
}
|
||||||
|
TEST_CASE("vector of one elements"){
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({3}, min, max);
|
||||||
|
CHECK(min == max);
|
||||||
|
}
|
||||||
|
TEST_CASE("mixed positive and negative numbers") {
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({-1, 2, 0, -3, 5}, min, max);
|
||||||
|
CHECK(min == -3);
|
||||||
|
CHECK(max == 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("vector with all negative numbers") {
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({-5, -10, -2}, min, max);
|
||||||
|
CHECK(min == -10);
|
||||||
|
CHECK(max == -2);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("vector with zero") {
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({0, -1, 1}, min, max);
|
||||||
|
CHECK(min == -1);
|
||||||
|
CHECK(max == 1);
|
||||||
|
}
|
||||||
|
TEST_CASE("empty vector") {
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({}, min, max);
|
||||||
|
CHECK(min == 0);
|
||||||
|
CHECK(max == 0);
|
||||||
|
}
|
||||||
137
unittest.depend
Обычный файл
137
unittest.depend
Обычный файл
@@ -0,0 +1,137 @@
|
|||||||
|
# depslib dependency file v1.0
|
||||||
|
1748808114 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\histogram.cpp
|
||||||
|
"histogram.h"
|
||||||
|
"histogram_internal.h"
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1748386910 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\histogram.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1748729850 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\unittest.cpp
|
||||||
|
"doctest.h"
|
||||||
|
"histogram_internal.h"
|
||||||
|
|
||||||
|
1748392747 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\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>
|
||||||
|
|
||||||
|
1748392232 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\histogram_internal.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1748811805 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\svg.cpp
|
||||||
|
"svg.h"
|
||||||
|
<iostream>
|
||||||
|
|
||||||
|
1748810901 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\svg.h
|
||||||
|
<vector>
|
||||||
|
<cstddef>
|
||||||
|
|
||||||
|
1748875465 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\histogram.cpp
|
||||||
|
"histogram.h"
|
||||||
|
"histogram_internal.h"
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1748386910 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\histogram.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1748392232 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\histogram_internal.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1749628551 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\svg.cpp
|
||||||
|
"svg.h"
|
||||||
|
<iostream>
|
||||||
|
|
||||||
|
1749627429 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\svg.h
|
||||||
|
<vector>
|
||||||
|
<cstddef>
|
||||||
|
|
||||||
|
1748875527 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\unittest.cpp
|
||||||
|
"doctest.h"
|
||||||
|
"histogram_internal.h"
|
||||||
|
|
||||||
|
1748392747 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\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>
|
||||||
|
|
||||||
5
unittest.layout
Обычный файл
5
unittest.layout
Обычный файл
@@ -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>
|
||||||
Ссылка в новой задаче
Block a user