|  |  |  | @ -3,6 +3,8 @@ | 
			
		
	
		
			
				
					|  |  |  |  | #include <iostream> | 
			
		
	
		
			
				
					|  |  |  |  | #include <conio.h> | 
			
		
	
		
			
				
					|  |  |  |  | #include <fstream> | 
			
		
	
		
			
				
					|  |  |  |  | #include "histogram.h" | 
			
		
	
		
			
				
					|  |  |  |  | #include "text.h" | 
			
		
	
		
			
				
					|  |  |  |  | using namespace std; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | const size_t SCREEN_WIDTH = 80; | 
			
		
	
	
		
			
				
					|  |  |  | @ -33,86 +35,10 @@ input_data(){ | 
			
		
	
		
			
				
					|  |  |  |  |     return in; | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | void | 
			
		
	
		
			
				
					|  |  |  |  | find_minmax(vector<double> numbers, double &min, double &max) | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |     min = numbers[0]; | 
			
		
	
		
			
				
					|  |  |  |  | 	max = numbers[0]; | 
			
		
	
		
			
				
					|  |  |  |  | 	for (size_t i = 1; i < numbers.size(); i++) | 
			
		
	
		
			
				
					|  |  |  |  |         { | 
			
		
	
		
			
				
					|  |  |  |  | 		if (min > numbers[i]) | 
			
		
	
		
			
				
					|  |  |  |  | 			min = numbers[i]; | 
			
		
	
		
			
				
					|  |  |  |  | 		if (max < numbers[i]) | 
			
		
	
		
			
				
					|  |  |  |  | 			max = numbers[i]; | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         return; | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | vector <size_t> make_histogramm(vector<double>numbers, size_t bin_count) | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |     double min, max; | 
			
		
	
		
			
				
					|  |  |  |  |     find_minmax(numbers, min, max); | 
			
		
	
		
			
				
					|  |  |  |  |     double binSize = (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 * binSize; | 
			
		
	
		
			
				
					|  |  |  |  | 			auto hi = min + (j + 1) * binSize; | 
			
		
	
		
			
				
					|  |  |  |  | 			if ((lo <= numbers[i]) && (numbers[i] < hi)) | 
			
		
	
		
			
				
					|  |  |  |  | 			{ | 
			
		
	
		
			
				
					|  |  |  |  | 				bins[j]++; | 
			
		
	
		
			
				
					|  |  |  |  | 				found = true; | 
			
		
	
		
			
				
					|  |  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 		if (!found) | 
			
		
	
		
			
				
					|  |  |  |  | 			bins[bin_count - 1]++; | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 	size_t max_count = bins[0]; | 
			
		
	
		
			
				
					|  |  |  |  | 	for (size_t i = 0; i < bin_count; i++) | 
			
		
	
		
			
				
					|  |  |  |  | 	{ | 
			
		
	
		
			
				
					|  |  |  |  | 		if (max_count < bins[i]) | 
			
		
	
		
			
				
					|  |  |  |  | 			max_count = bins[i]; | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 	if (max_count > 76) { | 
			
		
	
		
			
				
					|  |  |  |  |         for (size_t i = 0; i < bin_count; i++) { | 
			
		
	
		
			
				
					|  |  |  |  |             int count = bins[i]; | 
			
		
	
		
			
				
					|  |  |  |  |             size_t height = 76 * (static_cast<double>(count) / max_count); | 
			
		
	
		
			
				
					|  |  |  |  |             bins[i] = height; | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     return bins; | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | void show_histogramm(vector<size_t>bins) | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |     for (size_t i = 0; i < bins.size(); i++) | 
			
		
	
		
			
				
					|  |  |  |  |         { | 
			
		
	
		
			
				
					|  |  |  |  |         cout << bins[i] << "|"; | 
			
		
	
		
			
				
					|  |  |  |  |         for (size_t j = 0; j < bins[i]; j++) | 
			
		
	
		
			
				
					|  |  |  |  |             cout << "*"; | 
			
		
	
		
			
				
					|  |  |  |  |         cout << endl; | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     return; | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | int main() | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |     /*bool running;
 | 
			
		
	
		
			
				
					|  |  |  |  | 	int res; | 
			
		
	
		
			
				
					|  |  |  |  | 	running =true; | 
			
		
	
		
			
				
					|  |  |  |  | 	res = 0;*/ | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	Input in = input_data(); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	auto bins = make_histogramm(in.numbers, in.bin_count); | 
			
		
	
	
		
			
				
					|  |  |  | 
 |