|  |  | @ -3,50 +3,81 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | using namespace std; |  |  |  | using namespace std; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | int main() |  |  |  | void | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | find_minmax(const vector<double> numbers, double& min, double& max) | 
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |     const size_t SCREEN_WIDTH = 80; |  |  |  |     min = numbers[0]; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; |  |  |  |     max = numbers[0]; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     size_t number_count, bin_count, i, j; |  |  |  |     size_t number_count = numbers.size(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     for (size_t i = 1; i < number_count; i++) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     cerr << "Enter number count: "; |  |  |  |     { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     cin >> number_count; |  |  |  |         if (numbers[i] < min) | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             min = numbers[i]; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         else if (numbers[i] > max) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             max = numbers[i]; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     vector<double> numbers(number_count); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (i=0; i<number_count; i++) |  |  |  | struct Input | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |         cin>>numbers[i]; |  |  |  |     vector<double> numbers; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     size_t bin_count{}; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | }; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     cerr << "Enter bin_count: "; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     cin >> bin_count; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     vector<size_t> bins(bin_count); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     double min = numbers[0]; |  |  |  | Input | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     double max = numbers[0]; |  |  |  | input_data() | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     for (double x : numbers) |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (x < min) |  |  |  |     size_t number_count; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     cin >> number_count; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     vector<double> numbers(number_count); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     for (size_t i = 0; i < number_count; i++) | 
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |     { | 
			
		
	
		
		
			
				
					
					|  |  |  |             min = x; |  |  |  |         cin >> numbers[i]; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |         else if (x > max) |  |  |  | 
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     size_t bin_count; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     cin >> bin_count; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     Input in; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     in.numbers.resize(number_count); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     for (size_t i = 0; i < number_count; i++) | 
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |     { | 
			
		
	
		
		
			
				
					
					|  |  |  |             max = x; |  |  |  |         cin >> in.numbers[i]; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     cin >> in.bin_count; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     return in; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | vector<size_t> | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | make_histogram(vector<double> numbers, size_t bin_count) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     double min, max; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     vector<size_t> bins(bin_count); | 
			
		
	
		
		
			
				
					
					|  |  |  |     double bin_size = (max - min) / bin_count; |  |  |  |     double bin_size = (max - min) / bin_count; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     find_minmax(numbers, min, max); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     size_t number_count = numbers.size(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (i = 0; i < number_count; i++) |  |  |  |     for (size_t i = 0; i < number_count; i++) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |     { | 
			
		
	
		
		
			
				
					
					|  |  |  |         bool found = false; |  |  |  |         bool found = false; | 
			
		
	
		
		
			
				
					
					|  |  |  |         for (j = 0; (j < bin_count - 1) && !found; j++) |  |  |  |         for (size_t j = 0; (j < bin_count - 1) && !found; j++) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         { |  |  |  |         { | 
			
		
	
		
		
			
				
					
					|  |  |  |             auto lo = min + j * bin_size; |  |  |  |             auto lo = min + j * bin_size; | 
			
		
	
		
		
			
				
					
					|  |  |  |             auto hi = min + (j + 1) * bin_size; |  |  |  |             auto hi = min + (j + 1) * bin_size; | 
			
		
	
	
		
		
			
				
					|  |  | @ -61,41 +92,17 @@ int main() | 
			
		
	
		
		
			
				
					
					|  |  |  |             bins[bin_count - 1]++; |  |  |  |             bins[bin_count - 1]++; | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     size_t max_count = 76; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (i=1; i<bin_count; i++) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (bins[i] > max_count && bins[i] > 76) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             max_count=bins[i]; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     //for (i=0; i<bins[bin_count-1]; i++)
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         //for (j=0; j<bin_count; j++)
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             //if (bins[j]>i)
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 //cout<<"*";
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             //else
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 //cout<<" ";
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         //cout<<endl;
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     for(i=0; i<bin_count;i++){ |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (bins[i]>=100) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     cout<<bins[i]<<"|"; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (bins[i]<100 && bins[i]>=10) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     cout<<" "<<bins[i]<<"|"; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (bins[i]<10) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     cout<<"  "<<bins[i]<<"|"; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     size_t height = 76 * (static_cast<double>(bins[i]) / max_count); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     for(j=0;j< height;j++) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     cout<<"*"; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     cout<<endl;} |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     return 0; |  |  |  | int main() | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     auto in = input_data(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     auto bins = make_histogram(in.numbers, in.bin_count); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //show_histogram_text(bins, ...);
 | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |