|  |  |  | @ -1,6 +1,7 @@ | 
			
		
	
		
			
				
					|  |  |  |  | #include <iostream> | 
			
		
	
		
			
				
					|  |  |  |  | #include <vector> | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | #include "histogram.h" | 
			
		
	
		
			
				
					|  |  |  |  | #include "text.h" | 
			
		
	
		
			
				
					|  |  |  |  | struct Input{ | 
			
		
	
		
			
				
					|  |  |  |  |     std::vector<double> numbers; | 
			
		
	
		
			
				
					|  |  |  |  |     size_t bin_count{}; | 
			
		
	
	
		
			
				
					|  |  |  | @ -24,86 +25,11 @@ Input input_data() { | 
			
		
	
		
			
				
					|  |  |  |  |     return in; | 
			
		
	
		
			
				
					|  |  |  |  | }; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | using namespace std; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | int main() | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |     const size_t SCREEN_WIDTH = 80; | 
			
		
	
		
			
				
					|  |  |  |  |     const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     int number_count, bucket; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     cerr << "Enter number count: "; cin >> number_count; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     std::cerr << "Enter numbers: \n"; | 
			
		
	
		
			
				
					|  |  |  |  |     vector <double> numbers(number_count); | 
			
		
	
		
			
				
					|  |  |  |  |     for (int i = 0; i < number_count; i++) cin >> numbers[i]; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     float min = numbers[0]; | 
			
		
	
		
			
				
					|  |  |  |  |     float max = numbers[0]; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     for (float x : numbers) | 
			
		
	
		
			
				
					|  |  |  |  |     { | 
			
		
	
		
			
				
					|  |  |  |  |         if (x < min) min = x; | 
			
		
	
		
			
				
					|  |  |  |  |         else if (x > max) max = x; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     if (max == min) {// ïðîâåðêà íà àíîìàëèþ
 | 
			
		
	
		
			
				
					|  |  |  |  |         std::cout << " Unable to create a histogram." << std::endl; | 
			
		
	
		
			
				
					|  |  |  |  |         return 1; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     cerr << "Enter bucket: "; cin >> bucket; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     float k = (max - min) / bucket; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     if (numbers.empty()) {//áûëè ëè ââåäåíû ÷èñëà
 | 
			
		
	
		
			
				
					|  |  |  |  |         std::cout << "Empty. unable to  create histogram." << std::endl; | 
			
		
	
		
			
				
					|  |  |  |  |         return 1; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     vector <int> stolb(bucket); | 
			
		
	
		
			
				
					|  |  |  |  |     vector <int> proz(stolb); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     for (int j = 0; j < bucket; j++) stolb[j] = 0; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     for (int i = 0; i < number_count; i++) | 
			
		
	
		
			
				
					|  |  |  |  |     { | 
			
		
	
		
			
				
					|  |  |  |  |         bool flag = false; | 
			
		
	
		
			
				
					|  |  |  |  |         for (int j = 0; (j < bucket && !flag); j++) | 
			
		
	
		
			
				
					|  |  |  |  |         { | 
			
		
	
		
			
				
					|  |  |  |  |             if (numbers[i] >= (min + k * j) && numbers[i] < (min + k * (1 + j))) | 
			
		
	
		
			
				
					|  |  |  |  |             { | 
			
		
	
		
			
				
					|  |  |  |  |                 stolb[j]++; | 
			
		
	
		
			
				
					|  |  |  |  |                 flag = true; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         if (!flag) stolb[bucket - 1]++; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     int maxlen = 0; | 
			
		
	
		
			
				
					|  |  |  |  |     for (int j = 0; j < bucket; j++) | 
			
		
	
		
			
				
					|  |  |  |  |     { | 
			
		
	
		
			
				
					|  |  |  |  |         if (maxlen < stolb[j]) maxlen = stolb[j]; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     for (int j = 0; j < bucket; j++) | 
			
		
	
		
			
				
					|  |  |  |  |     { | 
			
		
	
		
			
				
					|  |  |  |  |         if (stolb[j] < 100) cout << " "; | 
			
		
	
		
			
				
					|  |  |  |  |         if (stolb[j] < 10) cout << ""; | 
			
		
	
		
			
				
					|  |  |  |  |         cout << stolb[j] << " |"; | 
			
		
	
		
			
				
					|  |  |  |  |         size_t height = stolb[j]; | 
			
		
	
		
			
				
					|  |  |  |  |         if (maxlen > MAX_ASTERISK) | 
			
		
	
		
			
				
					|  |  |  |  |         { | 
			
		
	
		
			
				
					|  |  |  |  |             if (maxlen != stolb[j]) height = MAX_ASTERISK * (static_cast <float>(stolb[j]) / maxlen); | 
			
		
	
		
			
				
					|  |  |  |  |             else if (maxlen == stolb[j]) height = MAX_ASTERISK; | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         for (int i = 0; i < height; i++) cout << "*"; | 
			
		
	
		
			
				
					|  |  |  |  |         cout << "\n"; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | int main() { | 
			
		
	
		
			
				
					|  |  |  |  |     Input in = input_data(); | 
			
		
	
		
			
				
					|  |  |  |  |     auto bins = make_histogram(in.numbers, in.bin_count); | 
			
		
	
		
			
				
					|  |  |  |  |     show_histogram_svg(bins); | 
			
		
	
		
			
				
					|  |  |  |  |     return 0; | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
	
		
			
				
					|  |  |  | 
 |