build: выполнена пересборка проекта

master
ArtyushinaVV 2 лет назад
Родитель 85bd0ada93
Сommit e4da0e1b1a

@ -1,12 +1,13 @@
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
#include <vector> #include <vector>
using namespace std; #include "histogram.h"
#include "text.h"
const size_t SCREEN_WIDTH = 80; using namespace std;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
struct Input { struct Input
{
vector<double> numbers; vector<double> numbers;
size_t bin_count{}; size_t bin_count{};
}; };
@ -15,106 +16,30 @@ Input
input_data() input_data()
{ {
size_t number_count; size_t number_count;
cerr << "count="; cerr << "count=";
cin >> number_count; cin >> number_count;
Input in;
in.numbers.resize(number_count);
for (size_t i = 0; i < number_count; i++) {
cin >> in.numbers[i];
}
cerr << "bin_count= ";
cin >> in.bin_count;
return in;
}
void
find_minmax(const vector<double>& numbers, double &min, double &max)
{
min = numbers[0];
max = numbers[0];
for (size_t i = 0; i < numbers.size(); i++)
{
if (numbers[i] > max)
max = numbers[i];
if (numbers[i] < min)
min = numbers[i];
}
}
vector <size_t> make_histogram (const vector<double>& numbers, size_t &bin_count)
{
vector <size_t> bins(bin_count);
double min, max;
float low, hi;
find_minmax(numbers, min, max); Input in;
double bin_size = (max - min) / bin_count; in.numbers.resize(number_count);
low = min;
hi = low + bin_size;
for (size_t i = 0; i < numbers.size(); i++) for (size_t i = 0; i < number_count; i++)
{
bool found = false;
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
{
low = min + j * bin_size;
hi = min + (j + 1) * bin_size;
if ((low <= numbers[i]) && (numbers[i] < hi))
{ {
bins[j]++; cin >> in.numbers[i];
found = true;
}
}
if (found==false)
{
bins[bin_count - 1]++;
}
} }
return bins;
}
void show_histogram_text(const vector<size_t>& bins, size_t &bin_count) cerr << "bin_count= ";
{ cin >> in.bin_count;
size_t max_bin = bins[0]; return in;
for (size_t bin : bins)
if (bin > max_bin)
max_bin = bin;
for (size_t bin : bins)
{
int height = bin;
if (max_bin > MAX_ASTERISK)
{
height = MAX_ASTERISK * (static_cast<double>(bin) / max_bin);
}
if (bin < 100)
cout << " ";
if (bin < 10)
cout << " ";
cout << bin << "|";
for (int i = 0; i < height; i++)
cout << "*";
cout << endl;
}
} }
int main() int main()
{ {
auto in = input_data(); auto in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count); auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_text(bins, in.bin_count); show_histogram_text(bins, in.bin_count);
return 0; return 0;
} }

Загрузка…
Отмена
Сохранить