|  |  | @ -3,25 +3,31 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | using namespace std; |  |  |  | using namespace std; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | int main() |  |  |  | struct Input { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  |     vector<double> numbers; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     size_t number_count; |  |  |  |     size_t bin_count{}; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     cerr << "Enter number count: "; |  |  |  | }; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | Input | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | input_data(){ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     size_t number_count, bin_count; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	cerr << "Enter number count: "; | 
			
		
	
		
		
			
				
					
					|  |  |  |     cin >> number_count; |  |  |  |     cin >> number_count; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     Input in; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     vector<double> numbers(number_count); |  |  |  |     in.numbers.resize(number_count); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     cerr << "Enter numbers: "; |  |  |  |     for (size_t i = 0; i < number_count; i++) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     for(size_t i = 0; i < number_count; i ++) |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |     { | 
			
		
	
		
		
			
				
					
					|  |  |  |         cin >> numbers[i]; |  |  |  |         cerr << "Enter Num[" << i << "]: "; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         cin >> in.numbers[i]; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     cerr << "Enter bin count: "; cin >> bin_count; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     size_t bin_count; |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     cerr << "Enter bin count: "; |  |  |  |     cerr << "Enter bin count: "; | 
			
		
	
		
		
			
				
					
					|  |  |  |     cin >> bin_count; |  |  |  |     cin >> in.bin_count; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     return in; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     double min = numbers[0]; |  |  |  | void find_minmax(const vector<double> &numbers, double &min, double &max){ | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     double max = numbers[0]; |  |  |  |     min = numbers[0]; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     max = numbers[0]; | 
			
		
	
		
		
			
				
					
					|  |  |  |     for(double number : numbers) |  |  |  |     for(double number : numbers) | 
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |     { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if(number < min) |  |  |  |         if(number < min) | 
			
		
	
	
		
		
			
				
					|  |  | @ -33,10 +39,15 @@ int main() | 
			
		
	
		
		
			
				
					
					|  |  |  |             max = number; |  |  |  |             max = number; | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     return; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     vector<size_t> bins(bin_count, 0); |  |  |  | } | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | vector<size_t> make_histogram (vector<double> numbers, size_t bin_count){ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     double min; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     double max; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     find_minmax (numbers, min, max); | 
			
		
	
		
		
			
				
					
					|  |  |  |     double bin_size = (max - min) / bin_count; |  |  |  |     double bin_size = (max - min) / bin_count; | 
			
		
	
		
		
			
				
					
					|  |  |  |     for(size_t i = 0; i < number_count; i++) |  |  |  |     vector<size_t> bins(bin_count); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     for (size_t i = 0; i < numbers.size(); i++) | 
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |     { | 
			
		
	
		
		
			
				
					
					|  |  |  |         bool found = false; |  |  |  |         bool found = false; | 
			
		
	
		
		
			
				
					
					|  |  |  |         for(size_t j = 0; (j < (bin_count - 1)) && !found; j++) |  |  |  |         for(size_t j = 0; (j < (bin_count - 1)) && !found; j++) | 
			
		
	
	
		
		
			
				
					|  |  | @ -54,7 +65,9 @@ int main() | 
			
		
	
		
		
			
				
					
					|  |  |  |             bins[bin_count-1]++; |  |  |  |             bins[bin_count-1]++; | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     return bins; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | void show_histogram_text(vector<size_t> bins, size_t bin_count){ | 
			
		
	
		
		
			
				
					
					|  |  |  |     const size_t SCREEN_WIDTH = 80; |  |  |  |     const size_t SCREEN_WIDTH = 80; | 
			
		
	
		
		
			
				
					
					|  |  |  |     const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; |  |  |  |     const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -91,5 +104,13 @@ int main() | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         cout << endl; |  |  |  |         cout << endl; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | int main() | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     auto in = input_data(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     auto bins = make_histogram(in.numbers, in.bin_count); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     show_histogram_text(bins, in.bin_count); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     return 0; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |