Родитель
							
								
									5451edd399
								
							
						
					
					
						Сommit
						14573b9b68
					
				| @ -0,0 +1,3 @@ | |||||||
|  | /bin | ||||||
|  | /obj | ||||||
|  | *.layout | ||||||
											
												
													Разница между файлами не показана из-за своего большого размера
													Загрузить разницу
												
											
										
									
								| @ -0,0 +1,42 @@ | |||||||
|  | #include "histogram.h" | ||||||
|  | 
 | ||||||
|  | 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; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | vector<size_t> | ||||||
|  | make_histogram(const vector<double>& numbers, size_t bin_count){ | ||||||
|  | 
 | ||||||
|  | double min, max; | ||||||
|  | find_minmax(numbers, min, max); | ||||||
|  | double bin_size = (max - min) / bin_count; | ||||||
|  | vector<size_t> bins(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; | ||||||
|  | } | ||||||
| @ -0,0 +1,11 @@ | |||||||
|  | #ifndef HISTOGRAM_H_INCLUDED | ||||||
|  | #define HISTOGRAM_H_INCLUDED | ||||||
|  | 
 | ||||||
|  | #include <vector> | ||||||
|  | 
 | ||||||
|  | std::vector<size_t> | ||||||
|  | make_histogram(const std::vector<double>& numbers, size_t bin_count); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | #endif // HISTOGRAM_H_INCLUDED
 | ||||||
|  | 
 | ||||||
| @ -0,0 +1,9 @@ | |||||||
|  | #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,19 @@ | |||||||
|  | # depslib dependency file v1.0 | ||||||
|  | 1686343289 source:c:\users\kostello\desktop\lubs\lab03.2\main.cpp | ||||||
|  | 	<string> | ||||||
|  | 	"histogram.h" | ||||||
|  | 	"text.h" | ||||||
|  | 
 | ||||||
|  | 1686342281 source:c:\users\kostello\desktop\lubs\lab03.2\histogram.cpp | ||||||
|  | 	"histogram.h" | ||||||
|  | 
 | ||||||
|  | 1686342254 c:\users\kostello\desktop\lubs\lab03.2\histogram.h | ||||||
|  | 	<vector> | ||||||
|  | 
 | ||||||
|  | 1686342636 source:c:\users\kostello\desktop\lubs\lab03.2\text.cpp | ||||||
|  | 	"text.h" | ||||||
|  | 
 | ||||||
|  | 1686343275 c:\users\kostello\desktop\lubs\lab03.2\text.h | ||||||
|  | 	<vector> | ||||||
|  | 	<iostream> | ||||||
|  | 
 | ||||||
| @ -0,0 +1,29 @@ | |||||||
|  | #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> | ||||||
|  | #include <iostream> | ||||||
|  | 
 | ||||||
|  | void show_histogram_text(std::vector <size_t> bins, size_t bin_count); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | #endif // TEXT_H_INCLUDED
 | ||||||
| @ -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> | ||||||
| @ -0,0 +1,45 @@ | |||||||
|  | #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 positive numbers") { | ||||||
|  |     double min = 0; | ||||||
|  |     double max = 0; | ||||||
|  |     find_minmax({}, min, max); | ||||||
|  |     CHECK(min == 0); | ||||||
|  |     CHECK(max == 0); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | TEST_CASE("distinct positive numbers") { | ||||||
|  |     double min = 0; | ||||||
|  |     double max = 0; | ||||||
|  |     find_minmax({1}, min, max); | ||||||
|  |     CHECK(min == 1); | ||||||
|  |     CHECK(max == 1); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 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 positive numbers") { | ||||||
|  |     double min = 0; | ||||||
|  |     double max = 0; | ||||||
|  |     find_minmax({2, 2, 2, 2}, min, max); | ||||||
|  |     CHECK(min == 2); | ||||||
|  |     CHECK(max == 2); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| @ -0,0 +1,7 @@ | |||||||
|  | # depslib dependency file v1.0 | ||||||
|  | 1686342281 source:c:\users\kostello\desktop\lubs\lab03.2\histogram.cpp | ||||||
|  | 	"histogram.h" | ||||||
|  | 
 | ||||||
|  | 1686342254 c:\users\kostello\desktop\lubs\lab03.2\histogram.h | ||||||
|  | 	<vector> | ||||||
|  | 
 | ||||||
					Загрузка…
					
					
				
		Ссылка в новой задаче