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

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

@ -1,12 +1,13 @@
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
#include "histogram.h"
#include "text.h"
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
using namespace std;
struct Input {
struct Input
{
vector<double> numbers;
size_t bin_count{};
};
@ -15,106 +16,30 @@ Input
input_data()
{
size_t number_count;
cerr << "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;
size_t number_count;
cerr << "count=";
cin >> number_count;
find_minmax(numbers, min, max);
Input in;
double bin_size = (max - min) / bin_count;
low = min;
hi = low + bin_size;
in.numbers.resize(number_count);
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]++;
found = true;
}
}
if (found==false)
{
bins[bin_count - 1]++;
}
cin >> in.numbers[i];
}
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];
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;
}
return in;
}
int main()
{
auto in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_text(bins, in.bin_count);
return 0;
}

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