Этот коммит содержится в:
RumyantsevVA
2023-09-14 22:01:04 +03:00
родитель 8f65fb9de1
Коммит be3f8e965f
36 изменённых файлов: 490 добавлений и 1 удалений

Двоичный файл не отображается.

Двоичные данные
.vs/main/FileContentIndex/2e6a0f7e-6aa0-4f82-b349-d4ec751de14d.vsidx Обычный файл

Двоичный файл не отображается.

Двоичный файл не отображается.

Двоичные данные
.vs/main/FileContentIndex/7b113ae9-d171-407b-bfd4-b0e3bb68fb87.vsidx Обычный файл

Двоичный файл не отображается.

Двоичный файл не отображается.

Двоичные данные
.vs/main/FileContentIndex/cf378d21-db5c-4c4a-abce-2b7654c5fdfe.vsidx Обычный файл

Двоичный файл не отображается.

Двоичные данные
.vs/main/FileContentIndex/feab0671-860f-42c9-9274-2376ad4dfd55.vsidx Обычный файл

Двоичный файл не отображается.

Двоичный файл не отображается.

Двоичные данные
.vs/main/v17/.suo

Двоичный файл не отображается.

Двоичные данные
.vs/main/v17/Browse.VC.db

Двоичный файл не отображается.

Двоичные данные
.vs/main/v17/ipch/AutoPCH/36d6937758d9d928/TEXT.ipch Обычный файл

Двоичный файл не отображается.

Двоичные данные
.vs/main/v17/ipch/AutoPCH/4a2d17197ab63958/SVG.ipch Обычный файл

Двоичный файл не отображается.

Двоичные данные
.vs/main/v17/ipch/AutoPCH/5658b55ff385d6e7/TEXT.ipch Обычный файл

Двоичный файл не отображается.

Двоичные данные
.vs/main/v17/ipch/AutoPCH/91c55d133da5222d/HISTOGRAM.ipch Обычный файл

Двоичный файл не отображается.

Двоичные данные
.vs/main/v17/ipch/AutoPCH/9400cee4c69d6b5/UNITTEST.ipch Обычный файл

Двоичный файл не отображается.

Двоичные данные
.vs/main/v17/ipch/AutoPCH/c9b472b49573e031/SVG.ipch Обычный файл

Двоичный файл не отображается.

Двоичные данные
.vs/main/v17/ipch/AutoPCH/d23161b53d28c5e4/HISTOGRAM.ipch Обычный файл

Двоичный файл не отображается.

Двоичные данные
.vs/unittest/FileContentIndex/31d7961d-8995-4a80-8dd1-c026fe1429fa.vsidx Обычный файл

Двоичный файл не отображается.

0
.vs/unittest/FileContentIndex/read.lock Обычный файл
Просмотреть файл

Двоичные данные
.vs/unittest/v17/.suo Обычный файл

Двоичный файл не отображается.

Двоичные данные
.vs/unittest/v17/Browse.VC.db Обычный файл

Двоичный файл не отображается.

52
histogram.cpp Обычный файл
Просмотреть файл

@@ -0,0 +1,52 @@
#include <iostream>
#include <vector>
#include "histogram.h"
//std::vector<size_t>
void
find_minmax(const std::vector<double> numbers, double& min, double& max)
{
/*/double/*/ min = numbers[0];//ïîèñê ìèí è ìàêñ
/*/ double/*/ max = 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);
double min, max;
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]++;
}
}
return bins;
}

Просмотреть файл

@@ -7,3 +7,4 @@ make_histogram(const std::vector<double> numbers, size_t bin_count);
#endif // HISTOGRAM_H_INCLUDED #endif // HISTOGRAM_H_INCLUDED

Просмотреть файл

@@ -4,7 +4,7 @@
#include "histogram.h" #include "histogram.h"
#include "text.h" #include "text.h"
#include "histogram_internal.h"
#include "svg.h" #include "svg.h"

117
svg.cpp Обычный файл
Просмотреть файл

@@ -0,0 +1,117 @@
#include <math.h>
#include <iostream>
#include <conio.h>
#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 vector<size_t>& bins, size_t number_count)
{
setlocale(LC_ALL, "Russian");
int noi = 0;
auto IMAGE_WIDTH = 0;
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;
//
cerr << "Ââåäèòå æåëàåìóþ øèðèíó ñòðîêè";
//cerr<<endl;
cerr << "Ó÷òèòå, ÷òî îíà äîëæíà áûòü áîëüøå 70 è ìåíüøå 800, à òàêæå";
// cerr<<endl;
cerr << "áîëåå òðåòè êîëè÷åñâà ÷èñåë, óìíîæåííûõ íà øèðèíó áëîêà .  âàøåì ñëó÷àå áîëåå " << ((number_count * BLOCK_WIDTH) / 3) << " ";
//cerr<<endl;
//cin>>IMAGE_WIDTH;
while (noi == 0)
{
cerr << " in cicle";
//cerr<<endl;
cin >> IMAGE_WIDTH;
if ((IMAGE_WIDTH < 800) && (IMAGE_WIDTH > 70) && (IMAGE_WIDTH > (number_count * BLOCK_WIDTH) / 3))
{
noi = noi + 1;
}
if (IMAGE_WIDTH > 800)
{
cerr << " ß æå ñêàçàë ìåíüøå 800. Ââåäèòå çàíîâî";
// cerr<<endl;
}
if (IMAGE_WIDTH < 70)
{
cerr << " ß æå ñêàçàë áîëüøå 70.Ââåäèòå çàíîâî";
//cerr<<endl;
}
if (IMAGE_WIDTH < (number_count * BLOCK_WIDTH) / 3)
{
cerr << " ß æå ñêàçàë áîëüøå " << (number_count * BLOCK_WIDTH) / 3 << " Ââåäèòå çàíîâî";
// cerr<<endl;
}
}
//string k;
//string m;
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));
/*/
cout<<"Ââåäèòå öâåò 1 â ôîðìàòå #RRGGBB";
cin>> k;
cout<<endl;
cout<<"Ââåäèòå öâåò 2 â ôîðìàòå #RRGGBB";
cin >> m;
/*/
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "#00CCFF" /*/k/*/, "#0000FF" /*/m/*/);
top += BIN_HEIGHT;
}
svg_end();
}

67
text.cpp Обычный файл
Просмотреть файл

@@ -0,0 +1,67 @@
#include <iostream>
#include <vector>
#include "text.h"
using namespace std;
void
show_histogram_text(vector<size_t> bins, size_t bin_count)
{
size_t max_count = 0;
for (size_t i = 0; i < bin_count; i++)
{
if (max_count < bins[i])
{
max_count = bins[i];
}
}
float procent;
for (size_t i = 0; i < bin_count; i++)
{
int procent = (float)bins[i];
if (procent < 10)
{
cout << " " << procent << " | ";
}
if ((procent < 100) && (procent >= 10))
{
cout << " " << procent << " | ";
}
size_t height = 0;
if (max_count > 76)
{
size_t height = 76 * (static_cast<double>(bins[i]) / max_count);
for (size_t j = 0; j <= height; j++)
{
cout << "*";
}
}
else
{
for (size_t j = 0; j <= bins[i] - 1; j++)
{
cout << "*";
}
}
cout << endl;
}
return;
}

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("vector 1 element")
{
double min = 0;
double max = 0;
find_minmax({ 1 }, min, max);
CHECK(min == 1);
CHECK(max == 1);
}
TEST_CASE("distinct negativ numbers")
{
double min = 0;
double max = 0;
find_minmax({ -1, -2 }, min, max);
CHECK(min == -2);
CHECK(max == -1);
}
TEST_CASE("distinct positive numbers")
{
double min = 0;
double max = 0;
find_minmax({ 2, 2 }, min, max);
CHECK(min == 2);
CHECK(max == 2);
}
TEST_CASE("distinct positive numbers")
{
double min = 0;
double max = 0;
//int n =2;
std::vector<double> pustoy;
CHECK(find_minmax(pustoy, min, max) == false);
/*/
CHECK(min == -2);
CHECK(max == -1);
/*/
/*/
double min = 0;
double max = 0;
std::vector<double> numbers {};
CHECK(find_minmax(numbers, min, max) == false);
/*/
}

31
unittest.sln Обычный файл
Просмотреть файл

@@ -0,0 +1,31 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unittest", "unittest.vcxproj", "{84936EC8-AB44-4C6C-B5B5-5E6F6337CBE0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{84936EC8-AB44-4C6C-B5B5-5E6F6337CBE0}.Debug|x64.ActiveCfg = Debug|x64
{84936EC8-AB44-4C6C-B5B5-5E6F6337CBE0}.Debug|x64.Build.0 = Debug|x64
{84936EC8-AB44-4C6C-B5B5-5E6F6337CBE0}.Debug|x86.ActiveCfg = Debug|Win32
{84936EC8-AB44-4C6C-B5B5-5E6F6337CBE0}.Debug|x86.Build.0 = Debug|Win32
{84936EC8-AB44-4C6C-B5B5-5E6F6337CBE0}.Release|x64.ActiveCfg = Release|x64
{84936EC8-AB44-4C6C-B5B5-5E6F6337CBE0}.Release|x64.Build.0 = Release|x64
{84936EC8-AB44-4C6C-B5B5-5E6F6337CBE0}.Release|x86.ActiveCfg = Release|Win32
{84936EC8-AB44-4C6C-B5B5-5E6F6337CBE0}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {658116EB-6F9F-4DD4-9BD9-DBF7E19EEE41}
EndGlobalSection
EndGlobal

138
unittest.vcxproj Обычный файл
Просмотреть файл

@@ -0,0 +1,138 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{84936ec8-ab44-4c6c-b5b5-5e6f6337cbe0}</ProjectGuid>
<RootNamespace>unittest</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared" >
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup></ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

17
unittest.vcxproj.filters Обычный файл
Просмотреть файл

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Исходные файлы">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Файлы заголовков">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Файлы ресурсов">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
</Project>

4
unittest.vcxproj.user Обычный файл
Просмотреть файл

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

Двоичные данные
x64/Debug/main.obj

Двоичный файл не отображается.

Двоичные данные
x64/Debug/main.pdb

Двоичный файл не отображается.

Двоичные данные
x64/Debug/main.tlog/CL.read.1.tlog

Двоичный файл не отображается.

Двоичные данные
x64/Debug/vc143.idb

Двоичный файл не отображается.

Двоичные данные
x64/Debug/vc143.pdb

Двоичный файл не отображается.