diff --git a/.vs/main/FileContentIndex/0b3c9c0b-3924-4815-bc4e-ba7086af98ea.vsidx b/.vs/main/FileContentIndex/0b3c9c0b-3924-4815-bc4e-ba7086af98ea.vsidx deleted file mode 100644 index d4066ed..0000000 Binary files a/.vs/main/FileContentIndex/0b3c9c0b-3924-4815-bc4e-ba7086af98ea.vsidx and /dev/null differ diff --git a/.vs/main/FileContentIndex/2e6a0f7e-6aa0-4f82-b349-d4ec751de14d.vsidx b/.vs/main/FileContentIndex/2e6a0f7e-6aa0-4f82-b349-d4ec751de14d.vsidx new file mode 100644 index 0000000..2911a47 Binary files /dev/null and b/.vs/main/FileContentIndex/2e6a0f7e-6aa0-4f82-b349-d4ec751de14d.vsidx differ diff --git a/.vs/main/FileContentIndex/5e99a61f-b374-4cc1-b2ae-c7c2dd80fbb4.vsidx b/.vs/main/FileContentIndex/5e99a61f-b374-4cc1-b2ae-c7c2dd80fbb4.vsidx deleted file mode 100644 index 77f8cb2..0000000 Binary files a/.vs/main/FileContentIndex/5e99a61f-b374-4cc1-b2ae-c7c2dd80fbb4.vsidx and /dev/null differ diff --git a/.vs/main/FileContentIndex/7b113ae9-d171-407b-bfd4-b0e3bb68fb87.vsidx b/.vs/main/FileContentIndex/7b113ae9-d171-407b-bfd4-b0e3bb68fb87.vsidx new file mode 100644 index 0000000..c51449a Binary files /dev/null and b/.vs/main/FileContentIndex/7b113ae9-d171-407b-bfd4-b0e3bb68fb87.vsidx differ diff --git a/.vs/main/FileContentIndex/7eccf379-c27e-4d74-ba05-ce2ebe609549.vsidx b/.vs/main/FileContentIndex/7eccf379-c27e-4d74-ba05-ce2ebe609549.vsidx deleted file mode 100644 index d4066ed..0000000 Binary files a/.vs/main/FileContentIndex/7eccf379-c27e-4d74-ba05-ce2ebe609549.vsidx and /dev/null differ diff --git a/.vs/main/FileContentIndex/cf378d21-db5c-4c4a-abce-2b7654c5fdfe.vsidx b/.vs/main/FileContentIndex/cf378d21-db5c-4c4a-abce-2b7654c5fdfe.vsidx new file mode 100644 index 0000000..c19a7ec Binary files /dev/null and b/.vs/main/FileContentIndex/cf378d21-db5c-4c4a-abce-2b7654c5fdfe.vsidx differ diff --git a/.vs/main/FileContentIndex/feab0671-860f-42c9-9274-2376ad4dfd55.vsidx b/.vs/main/FileContentIndex/feab0671-860f-42c9-9274-2376ad4dfd55.vsidx new file mode 100644 index 0000000..9c70de6 Binary files /dev/null and b/.vs/main/FileContentIndex/feab0671-860f-42c9-9274-2376ad4dfd55.vsidx differ diff --git a/.vs/main/FileContentIndex/ff2f57f6-df70-4009-a897-d39335368737.vsidx b/.vs/main/FileContentIndex/ff2f57f6-df70-4009-a897-d39335368737.vsidx deleted file mode 100644 index d4066ed..0000000 Binary files a/.vs/main/FileContentIndex/ff2f57f6-df70-4009-a897-d39335368737.vsidx and /dev/null differ diff --git a/.vs/main/v17/.suo b/.vs/main/v17/.suo index 16433bd..ac55ff2 100644 Binary files a/.vs/main/v17/.suo and b/.vs/main/v17/.suo differ diff --git a/.vs/main/v17/Browse.VC.db b/.vs/main/v17/Browse.VC.db index f85e23e..cef6340 100644 Binary files a/.vs/main/v17/Browse.VC.db and b/.vs/main/v17/Browse.VC.db differ diff --git a/.vs/main/v17/ipch/AutoPCH/36d6937758d9d928/TEXT.ipch b/.vs/main/v17/ipch/AutoPCH/36d6937758d9d928/TEXT.ipch new file mode 100644 index 0000000..602dcd3 Binary files /dev/null and b/.vs/main/v17/ipch/AutoPCH/36d6937758d9d928/TEXT.ipch differ diff --git a/.vs/main/v17/ipch/AutoPCH/4a2d17197ab63958/SVG.ipch b/.vs/main/v17/ipch/AutoPCH/4a2d17197ab63958/SVG.ipch new file mode 100644 index 0000000..6f2a55c Binary files /dev/null and b/.vs/main/v17/ipch/AutoPCH/4a2d17197ab63958/SVG.ipch differ diff --git a/.vs/main/v17/ipch/AutoPCH/5658b55ff385d6e7/TEXT.ipch b/.vs/main/v17/ipch/AutoPCH/5658b55ff385d6e7/TEXT.ipch new file mode 100644 index 0000000..f15f1f3 Binary files /dev/null and b/.vs/main/v17/ipch/AutoPCH/5658b55ff385d6e7/TEXT.ipch differ diff --git a/.vs/main/v17/ipch/AutoPCH/91c55d133da5222d/HISTOGRAM.ipch b/.vs/main/v17/ipch/AutoPCH/91c55d133da5222d/HISTOGRAM.ipch new file mode 100644 index 0000000..ef18808 Binary files /dev/null and b/.vs/main/v17/ipch/AutoPCH/91c55d133da5222d/HISTOGRAM.ipch differ diff --git a/.vs/main/v17/ipch/AutoPCH/9400cee4c69d6b5/UNITTEST.ipch b/.vs/main/v17/ipch/AutoPCH/9400cee4c69d6b5/UNITTEST.ipch new file mode 100644 index 0000000..f33ec8c Binary files /dev/null and b/.vs/main/v17/ipch/AutoPCH/9400cee4c69d6b5/UNITTEST.ipch differ diff --git a/.vs/main/v17/ipch/AutoPCH/c9b472b49573e031/SVG.ipch b/.vs/main/v17/ipch/AutoPCH/c9b472b49573e031/SVG.ipch new file mode 100644 index 0000000..fb81573 Binary files /dev/null and b/.vs/main/v17/ipch/AutoPCH/c9b472b49573e031/SVG.ipch differ diff --git a/.vs/main/v17/ipch/AutoPCH/d23161b53d28c5e4/HISTOGRAM.ipch b/.vs/main/v17/ipch/AutoPCH/d23161b53d28c5e4/HISTOGRAM.ipch new file mode 100644 index 0000000..314a41b Binary files /dev/null and b/.vs/main/v17/ipch/AutoPCH/d23161b53d28c5e4/HISTOGRAM.ipch differ diff --git a/.vs/unittest/FileContentIndex/31d7961d-8995-4a80-8dd1-c026fe1429fa.vsidx b/.vs/unittest/FileContentIndex/31d7961d-8995-4a80-8dd1-c026fe1429fa.vsidx new file mode 100644 index 0000000..fcc8409 Binary files /dev/null and b/.vs/unittest/FileContentIndex/31d7961d-8995-4a80-8dd1-c026fe1429fa.vsidx differ diff --git a/.vs/unittest/FileContentIndex/read.lock b/.vs/unittest/FileContentIndex/read.lock new file mode 100644 index 0000000..e69de29 diff --git a/.vs/unittest/v17/.suo b/.vs/unittest/v17/.suo new file mode 100644 index 0000000..af2ac46 Binary files /dev/null and b/.vs/unittest/v17/.suo differ diff --git a/.vs/unittest/v17/Browse.VC.db b/.vs/unittest/v17/Browse.VC.db new file mode 100644 index 0000000..72fcff1 Binary files /dev/null and b/.vs/unittest/v17/Browse.VC.db differ diff --git a/histogram.cpp b/histogram.cpp new file mode 100644 index 0000000..964ad42 --- /dev/null +++ b/histogram.cpp @@ -0,0 +1,52 @@ +#include +#include +#include "histogram.h" + +//std::vector + +void +find_minmax(const std::vector 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 +make_histogram(const std::vector numbers, size_t bin_count) +{ + std::vector 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; +} diff --git a/histogram.h b/histogram.h index 53f46da..d1b1414 100644 --- a/histogram.h +++ b/histogram.h @@ -7,3 +7,4 @@ make_histogram(const std::vector numbers, size_t bin_count); #endif // HISTOGRAM_H_INCLUDED + diff --git a/main.cpp b/main.cpp index dc61a83..86a60f3 100644 --- a/main.cpp +++ b/main.cpp @@ -4,7 +4,7 @@ #include "histogram.h" #include "text.h" - +#include "histogram_internal.h" #include "svg.h" diff --git a/svg.cpp b/svg.cpp new file mode 100644 index 0000000..1d12cda --- /dev/null +++ b/svg.cpp @@ -0,0 +1,117 @@ +#include +#include +#include +#include +#include +#include "svg.h" +using namespace std; + +void +svg_begin(double width, double height) +{ + cout << "\n"; + cout << "\n"; +} + +void +svg_end() +{ + cout << "\n"; +} +void +svg_text(double left, double baseline, string text) +{ + cout << "" << text << ""; +} + +void +svg_rect(double x, double y, double width, double height, string stroke, string fill) +{ + cout << ""; + +} + + +void +show_histogram_svg(const vector& 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<>IMAGE_WIDTH; + while (noi == 0) + { + cerr << " in cicle"; + //cerr<> 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< 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<> m; + /*/ + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "#00CCFF" /*/k/*/, "#0000FF" /*/m/*/); + top += BIN_HEIGHT; + } + + svg_end(); +} diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..b501250 --- /dev/null +++ b/text.cpp @@ -0,0 +1,67 @@ +#include +#include +#include "text.h" + +using namespace std; + +void +show_histogram_text(vector 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(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; +} diff --git a/unittest.cpp b/unittest.cpp new file mode 100644 index 0000000..223e60a --- /dev/null +++ b/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 pustoy; + + CHECK(find_minmax(pustoy, min, max) == false); + + /*/ + CHECK(min == -2); + CHECK(max == -1); + /*/ + /*/ + double min = 0; + double max = 0; + std::vector numbers {}; + CHECK(find_minmax(numbers, min, max) == false); + /*/ +} + + + diff --git a/unittest.sln b/unittest.sln new file mode 100644 index 0000000..ed26c4a --- /dev/null +++ b/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 diff --git a/unittest.vcxproj b/unittest.vcxproj new file mode 100644 index 0000000..12569f2 --- /dev/null +++ b/unittest.vcxproj @@ -0,0 +1,138 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + 16.0 + Win32Proj + {84936ec8-ab44-4c6c-b5b5-5e6f6337cbe0} + unittest + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + diff --git a/unittest.vcxproj.filters b/unittest.vcxproj.filters new file mode 100644 index 0000000..153170c --- /dev/null +++ b/unittest.vcxproj.filters @@ -0,0 +1,17 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + \ No newline at end of file diff --git a/unittest.vcxproj.user b/unittest.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/unittest.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/x64/Debug/main.obj b/x64/Debug/main.obj index b935469..97550c9 100644 Binary files a/x64/Debug/main.obj and b/x64/Debug/main.obj differ diff --git a/x64/Debug/main.pdb b/x64/Debug/main.pdb index 47b4734..6c47a6f 100644 Binary files a/x64/Debug/main.pdb and b/x64/Debug/main.pdb differ diff --git a/x64/Debug/main.tlog/CL.read.1.tlog b/x64/Debug/main.tlog/CL.read.1.tlog index b050ff8..2c176de 100644 Binary files a/x64/Debug/main.tlog/CL.read.1.tlog and b/x64/Debug/main.tlog/CL.read.1.tlog differ diff --git a/x64/Debug/vc143.idb b/x64/Debug/vc143.idb index eab5ffc..5d09c00 100644 Binary files a/x64/Debug/vc143.idb and b/x64/Debug/vc143.idb differ diff --git a/x64/Debug/vc143.pdb b/x64/Debug/vc143.pdb index f2815e5..a6b2f46 100644 Binary files a/x64/Debug/vc143.pdb and b/x64/Debug/vc143.pdb differ