|
|
|
@ -19,10 +19,13 @@ input_data() {
|
|
|
|
|
for (size_t i = 0; i < number_count; i++) {
|
|
|
|
|
cin >> in.numbers[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cerr << "Enter bin count: ";
|
|
|
|
|
cin >> in.bin_count;
|
|
|
|
|
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
find_minmax(const vector<double>& numbers, double& min, double& max) {
|
|
|
|
|
min = numbers[0];
|
|
|
|
@ -36,15 +39,16 @@ find_minmax(const vector<double>& numbers, double& min, double& max) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vector <double>
|
|
|
|
|
make_histogram(const vector<double>& numbers, size_t bin_count){
|
|
|
|
|
vector<double> bins (bin_count);
|
|
|
|
|
|
|
|
|
|
double min = 0, max = 0;
|
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
|
|
|
|
|
|
double bin_size = (max - min) / bin_count;
|
|
|
|
|
for (int i = 0; i < numbers.size(); i++) {
|
|
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
|
for (int j = 0; (j < bin_count - 1) && !found; j++) {
|
|
|
|
|
auto lo = min + j * bin_size;
|
|
|
|
@ -57,19 +61,19 @@ make_histogram(const vector<double>& numbers, size_t bin_count){
|
|
|
|
|
if (!found) {
|
|
|
|
|
bins[bin_count - 1]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return bins;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
show_histogram_text (const vector<double>& bins,size_t MAX_ASTERISK, size_t bin_count){
|
|
|
|
|
|
|
|
|
|
double max_count = bins[0];
|
|
|
|
|
for (double x: bins){
|
|
|
|
|
if (x > max_count) {
|
|
|
|
|
max_count = x;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < bin_count; i++){
|
|
|
|
|
double count = bins[i];
|
|
|
|
|
size_t height = MAX_ASTERISK * (static_cast<double>(count) / max_count);
|
|
|
|
@ -80,7 +84,7 @@ show_histogram_text (const vector<double>& bins,size_t MAX_ASTERISK, size_t bin_
|
|
|
|
|
{cout << ' ';}
|
|
|
|
|
cout << bins[i] << "|" << line << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
const size_t SCREEN_WIDTH = 80;
|
|
|
|
|